parent child many

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keevitaja
Forum Newbie
Posts: 8
Joined: Wed Feb 25, 2009 7:46 am

parent child many

Post by keevitaja »

hello,

i'm trying to create a recrusive parent child meny on my site. somehow my code doesn't work:

Code: Select all

    function LoadMeny($parent_id = 0, $level = 0)
    {
        global $db;
    $query = $db->query("SELECT page_id, parent_id FROM ".DB_PAGES."
            WHERE parent_id='$parent_id' ORDER BY order_id"
    );
    
    $meny = array();
    
    while($row = $db->fetch_array($query))
    {
        $meny[] = array(
            'page_id' => $row['page_id'],
            'level' => $level
        );
    
        $meny = array_merge($meny, LoadMeny($row['parent_id'], $level + 1));
    }
    
    return $meny;
  }
what am i doing wrong? there are following columns in my database: page_id, order_id, parent_id + subject, text etc
Post Reply