Dynamic menu with PHP

0

The menu is almost ready, in the last part I'm facing a problem with foreach , as the right side of the image demonstrates (the menu on the left is still the mechanical menu).

Forthecategories,I'llfirstneedtheirid,sofarsogood.Theproblemisforeachisrepeatingtheids:

<?php$sql_2_a=mysqli_query($config,"SELECT DISTINCT menu FROM recursos ORDER BY menu ASC") or die(mysqli_error($config));
if(@mysqli_num_rows($sql_2_a) <= '0'){
    echo "
        <div class=\"row\">
            <div class=\"col-lg-6\">
                <div class=\"alert alert-danger\">
                    <strong>Erro!</strong> $erro
                </div>
            </div>      
        </div>
        ";
    }else{
        while($r_sql_2_a = mysqli_fetch_array($sql_2_a)){
            $id_menu_sel = $r_sql_2_a[0];

            $sql_3 = mysqli_query($config, "SELECT url FROM recursos WHERE menu = '$id_menu_sel'") or die(mysqli_error($config));
            if(@mysqli_num_rows($sql_3) <= '0'){
                echo "
                    <div class=\"row\">
                        <div class=\"col-lg-6\">
                            <div class=\"alert alert-danger\">
                                <strong>Erro!</strong> $erro
                            </div>
                        </div>      
                    </div>
                    ";
                }else{
                    $p = Array();
                    while($r_sql_3 = mysqli_fetch_array($sql_3)){
                        $p[] = $r_sql_3[0];

                    }
                }



                foreach ($p as $key => $value) {
                    if($value==$pagina_link){
                        echo "<b>".$id_menu_sel."</b>";
                    }else{
                        echo $id_menu_sel;
                    }
                }
            }
        }
?>

What is repeating is this foreach ($p as $key => $value) , already tried to change the beginning of the loop, but nothing.

    
asked by anonymous 30.10.2018 / 04:15

1 answer

-1

From what I understand there, it's repeating because you're passing everything to the while, and then traversing again with the foreach, implement the foreach from mysqli_fetch_array because it already generates a scrollable array. I think it should work!

    
30.10.2018 / 12:43