Too many iterations for second if statement which lists extra blank bullet

$sqlAandM = "SELECT * FROM #_directoryBase_categories WHERE parent_id='1' LIMIT 6";
    $getAandM =  $wpdb->get_results($sqlAandM, ARRAY_A);
    $listAandMMain = "";
        foreach ($getAandM as $getAandMExtend){

                    if($getAandMExtend[is_parent] = "yes") {
                        $listAandMMain .= "$getAandMExtend[dir_categories]";
                        //echo $listAandMMain;
                    }
                    elseif($getAandMExtend[is_parent] = "no") {
                        $listAandMSub .= "<li>$getAandMExtend[dir_sub_categories]</li>";                        
                    }

        }

MYSQL TABLE Structure:

enter image description here

Read More

This is currently outputting

Visual of what is being outputted:

enter image description here

Notice that for some reason the a blank list item has been added to the out put for the sub categories. I’m limiting to only 6 as I’ll style them below the “Advertisign and Media” main category item.

Is there something that can be done to skip that extra iteration without directly targeting it through mysql with separate queries?

I don’t have enough rep to post images within the body, but they add a ton of clarity of what exactly is happening.

Related posts

Leave a Reply

1 comment

  1. Pretty sure:

                   if($getAandMExtend[is_parent] = "yes") {
                        $listAandMMain .= "$getAandMExtend[dir_categories]";
                        //echo $listAandMMain;
                    }
                    elseif($getAandMExtend[is_parent] = "no") {
                        $listAandMSub .= "<li>$getAandMExtend[dir_sub_categories]</li>";                        
                    }
    

    should be

                   if($getAandMExtend[is_parent] == "yes") {
                        $listAandMMain .= "$getAandMExtend[dir_categories]";
                        //echo $listAandMMain;
                    }
                    elseif($getAandMExtend[is_parent] == "no") {
                        $listAandMSub .= "<li>$getAandMExtend[dir_sub_categories]</li>";                        
                    }
    

    Because two equals (==) is asking if x is equals to y.
    One equals (=) is x is equals to the contents of y and therefore won’t compare the two.

    So from the above you want == as you are comparing not values not assigning them.