I am trying to dynamically add categories
in navigation bar, but it keeps on giving this error:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\includes\navigation.php on line 11
My PHP Code:
<?php
$sql = "SELECT * FROM categories WHERE parent = 0";
$result=mysqli_query($db,$sql);
?>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<a href="home.php" class="navbar-brand">Bizibay</a>
<ul class="nav navbar-nav">
<?php while($row=mysqli_fetch_array($result, MYSQLI_ASSOC)) : ?>
<!-- top menu items -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Men<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Shirts</a></li>
<li><a href="#">Pants</a></li>
<li><a href="#">Shoes</a></li>
<li><a href="#">Accessories</a></li>
</ul>
</li>
</ul>
<?php endwhile; ?>
</div>
</nav>
Try this version. It contains: prepared statements, exception handling and error reporting/display. I hope it will help you in finding out the solution. At first sight it seems that your fetching returns NULL. So the problem is given by
mysqli_query()
.I wrote two versions, actually. You can use the OOP style (my recommendation) by including "oopFunctions.php" in "index.php", or you can instead use the procedural style by including "proceduralFunctions.php" in "index.php".
Good luck!
MySQLi with prepared statements and exception handling
index.php (main page)
configs.php
proceduralFunctions.php
oopFunctions.php