Below are 2 functions that will handle the Query and rending of the menu from MySQL Database.

This function Loops through the array. Takes in 2 arguments.

    function loop_section($array, $parent_id = 0){
        echo '<ul>';
            foreach($array as $section){
                echo '<li>';
                echo $section->section_name;
                echo '</li>';
        echo '</ul>';

This function handles the Querying of the menu from the table section in the database.

function fetch_sections(){
        global $db;
        $array = array();
        $query = $db->SELECT("SELECT * FROM sections");
        $array = $db->ROWS();

At the moment when I run this, I get all the menu as the same, I mean all of them renders as first level format. What am I missing over here?

Edited by navneil

3 Years
Discussion Span
Last Post by broj1

Well you will do as you are selecting all records and echoing them out through one loop all in the same unordered list. What exactly are you trying to do?


Check what the $array content is. Is it an array of objetcs (this is how you reffer to each row)?

To check the contents of the array insert this temporary debug code after line 5 in the second code snippet:

die(print_r($array, 1));

This will display the contents of the $array variable and stop the script. Now you can inspect the elements displayed and try to debug it. You can also paste the output here for us to see.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.