I have two tables in a database called categories and products, I need to interconnect them and show all related products under each category and following is my approach.
<table class="table table-striped">
<tr>
<th>product id</th>
<th>product name</th>
<th>category name</th>
</tr>
<?php
mysql_connect("localhost","root");
mysql_select_db("inventory");
$res=mysql_query("SELECT c.* , p.* FROM categories c,products p WHERE c.id=p.category_id");
while($row=mysql_fetch_array($res))
{
?>
<tr>
<td><p><?php echo $row['name']; ?></p></td>
<td><p><?php echo $row['name']; ?></p></td>
</tr>
<?php
}
?>
</table>
But it throws an error
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 27