Click here to Skip to main content
15,071,262 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am making a website of a resturant. in database I have created two tables
1-food(id,food_name,cat_id(F.K),)
2-category(cat_id,cat_name)

I want to display the category in navigation bar and on clicking the category it has to show the respected food that comes under the category.

example I have the following entries in my table
food_name=Zinger Burger,Chicken Burger,Sea Food
cat_name=FastFood,Fish

how can I show the category on menu bar as a hyperlink and on clicking the shows the food from database that is onclicking the fastfood it shows the zinger and chicken burger.

below is my work which I have done so far

PHP
?php  
 $query="Select * from category";
  $result=mysql_query($query,$connection);
  while($category=mysql_fetch_array($result))
  {?>
	   <ul>
        <li>
     <?php  $category["cat_name"]; <br mode="hold" /?>  
   
echo "<a href="\"show.php\"">  ".$category['cat_name'] ." </a>";
}?&gt;
</li>
</ul>
<?php <br mode="hold" /?>
//$food="Select * from food where cat_id={$category["cat_id"]} ";
        $query = "SELECT * ";
		$query .= "FROM subjects ";
		$query .= "WHERE cat_id=" . $category["cat_id"] ." ";

$result1=mysql_query($query,$connection);
  
while($foodname=mysql_fetch_array($result1))
   {
	echo"<li> {$foodname["food_name"]}</li>";
	}
echo "";

?>
Posted
Updated 6-Jul-12 23:48pm
v2

1 solution

Just pass the category id in your show.php as query string and from there you may be able to query the food table.
   
Comments
wajahat134 9-Jul-12 4:19am
   
please elaborate how can I do it??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900