I'm trying to display a menu category followed by all the menu items that fall under that category using nested while statements.
In the nested while loop I need for it to only print the items for that category.PHP Code:<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
('Error connecting to mysql');
$dbname = 'Restaurant';
mysql_select_db($dbname);
$querymenucategory = "SELECT MenuCategoryID, MenuCategoryName FROM universitymenucategory";
$resultmenucategory = mysql_query($querymenucategory);
$querymenuitem = "SELECT MenuCategoryID, ItemName, ItemCost, ItemDescription FROM universitymenu";
$resultmenuitem = mysql_query($querymenuitem);
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>Menu</title>
<link href=\"../CSSFolder/menu.css\" rel=\"stylesheet\" type=\"text/css\" />
</head>
<body>
<div id =\"container\">
<div class =\"horbar\">
<a href=\"../index.htm\">Home</a>
<a href=\"menu.htm\">Menu</a>
<a href=\"wine.htm\">Wine</a>
<a href=\"specials.htm\">Specials</a>
<a href=\"events.htm\">Events</a>
<a href=\"map.htm\">Map</a>
<a href=\"contact.htm\">Contact</a></div>
<div id=\"menu-container\">
<div class=\"gutter\">\n";
while($row = mysql_fetch_array($resultmenucategory, MYSQL_ASSOC))
{
echo "<h2 class =\"menu-category\">{$row['MenuCategoryName']}</h2>\n" .
"<dl>\n";
while($row = mysql_fetch_array($resultmenuitem, MYSQL_ASSOC))
{
echo "<dt>{$row['ItemName']}</dt>\n" .
"<dd class =\"price\">{$row['ItemCost']}</dd>\n" .
"<dd class =\"ingredients\">{$row['ItemDescription']}</dd>\n";
}
echo "</dl>\n";
}
echo "
</div><!--end gutter-->
</div><!--end menu-container-->
</div><!--end container-->
</body>
</html>";
?>
This is the DB structure of the 2 tables.
The first table name is "universitymenucategory" and its fields are "MenuCategoryID, MenuCategoryName".
The second table name is "universitymenu" and its fields are "MenuCategoryID, ItemName, ItemCost, ItemDescription".
So basically I need the "MenuCategoryID" field to match as the loops iterate the DB.
If you were wondering, no this isn't a college assignment. I haven't be in school for quite some time now. The restaurant is located near Rice so they call it the university location.
I'm not a programmer, I've only read a couple of books. Please don't be too cruel.
Many thanks for your time,
Joe
