Hi everyone! Been hitting my head against the wall with this one for a week now and still cant get my head around it. My knowledge with PHP is good in some areas but lacking in others. Working on it though. I am trying to make a dynamic menu from a database of a CMS I made. The info is bellow.
I have the following code:
[php] function menu($parent, $level){
global $dbc;
$result = $dbc->prepare('SELECT linktext, visible, sort FROM content WHERE parent =? ORDER BY sort');
$result->bind_param('s', $parent);
$result->execute();
$result->bind_result($menu_linktext, $menu_visible, $menu_sort);
$total_records = $result->num_rows;
if($level > 0 && $total_records > 0){
echo '<ul>';
}
while($row = $result->fetch()){
echo "<li>";
echo '<a href="?page=' . $menu_linktext . '">' . $menu_linktext . '</a>'.$id;
//display this level's children
menu($id, $level+1);
echo "</li>\n";
}
if($level > 0 && $total_records > 0){
echo '</ul>';
}
}
echo '<ul>' . menu(0,0) . '</ul>'[/php]
It works for one link (Home) then throws out a Call to a member function bind_param() on a non-object error.
The basics of the table is there are other columns page content etc but those arenāt needed in this:
[php] ļæ¼page | linktext | visable | parent | sort
1 Home 1 0 1
2 Gallery 1 0 3
3 About Us 1 0 2
4 Contact Us 1 0 5
5 Services 1 0 4
6 Diving 0 5 1
7 Angling 0 5 2
8 Charters 0 5 3
[/php]
Here is the HTML structure that hopefully should be outputted!:
[php]
[/php]If you need more info/ code I can post if for you.
I want to get the basic menu working then work on the sort order of the links. If anyone can help it would be very much appreciated. I will try and help others if I can.