I'm having a little problem displaying data from a database...
I have two database tables:
- categories(cat_id, cat_name)
- menu_items(menu_id, menu_name, cat_id, menu_description, menu_price)
I would like to display data as:
Categorie 1 Name
- cat_id = 1, menu_name, menu_description, menu_price
- cat_id = 1, menu_name, menu_description, menu_price
- cat_id = 1, ...
Categorie 2 Name
- cat_id = 2, menu_name, menu_description, menu_price
- cat_id = 2, menu_name, menu_description, menu_price
- cat_id = 2, ...
Categorie 3 Name
- cat_id = 3, menu_name, menu_description, menu_price
- cat_id = 3, menu_name, menu_description, menu_price
- cat_id = 3, ....
...
My code:
function get_menu_items() {
// query database for a list of categories
$conn = db_connect();
$query = "select cat_id, cat_name from categories";
$result = @$conn->query($query);
if (!$result) {
return false;
}
$num_cats = @$result->num_rows;
if ($num_cats == 0) {
return false;
}
$result = db_result_to_array($result);
return $result;
}
function display_menu_items($menu_array) {
if (!is_array($menu_array)) {
echo "<p>No menu items currently available</p>";
return;
}
foreach ($menu_array as $row) {
echo "<section id='".$row['cat_name']."'>";
echo "<div class='group course'>";
echo "<h3>".$row['cat_name']."</h3>";
***/* Problem */***
echo "<ul>";
foreach... {
echo "<li>cat_id = #, menu_name, menu_description, menu_price</li>";
}
echo "</ul>
***/* Problem */***
echo "</div>";
echo "</section>";
}
}
Any suggestions?
Thanks.