Hi every one. I have a bit of a problem/ headache. I am trying to make a dropdown style menu for a website that runs off a CMS I made everything works fine but I can for the life of me get the menu system to work! This is the code I have:

function display_child($parent, $level){
    $result = $dbc->prepare('SELECT linktext, visible, sort, parent FROM content WHERE parent =? ORDER BY sort');
    $result->bind_param('s', $parent);
    $result->execute();
    $result->bind_result($menu_linktext, $menu_visible, $menu_sort, $sparent);

    while ($row = $result->fetch()) {

    echo "<li>".$menu_linktext."</li>\n";

    display_child($sparent, $level+1);  

    }
    }
        display_child('','0');

I just hangs when I run it or gives me a : Call to a member function prepare() on a non-object error depending on its mood..

have you created the object properly? i mean what is $dbc

$dbc is:

$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );

I have other scripts on the site that work pefectly fine with this.

I have also came up with this:

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>'

Which works for one link!

This is the data for the table:

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

And the HTML output:

<ul class="sf-menu" id="nav">
          <li><a href="index.html">Home</a></li>
          <li><a href="about.html">Examples</a></li>
          <li><a href="gallery.html">A Page</a></li>
          <li><a href="#">Services</a>
            <ul>
              <li><a href="#">Diving</a></li>
              <li><a href="#">Angling</a>
              <li><a href="#">Charter</a></li>
            </ul>
          </li>
          <li><a href="contact.html">Contact Us</a></li>
        </ul>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.