Jump to content

[SOLVED] DB help please


forumnz

Recommended Posts

I have 3 tables for a Menu feature.

 

Table one has the menuid and the userid (to match it all up) and the names of menus (like breakfast, dinner, lunch etc).

Table 2 has the menu section names (like Cooked Breakfast, Quick Breakfast etc).

Table 3 has all the menu items (like, cereal, toast etc).

 

I have it sorted so that the user can click on 'Breakfast' and that takes them to index.php?id=1 <-- menu no.

I have some code, which should list all the menu section names, and it's options underneath.

Like:

Cooked Breakfast:

  Toast

  Eggs

  etc

 

Quick Breakfast

  Fruit

  Cereal

  etc

 

Problem is, my code only displays one row and it's options. (Cooked Breakfast: Toast, Eggs, etc).

 

Here is my code:

 

<?php
include('connectdb.php');
$id = $_GET['id'];

$sql ="SELECT * FROM `menu_headers` WHERE `menuhid`='$id'";
$result = mysql_query($sql) or die(mysql_error());
$numr = mysql_num_rows($result);

while($row = mysql_fetch_array($result))
  {
  $name = $row['name'];
  $menuid = $row['id'];
  echo "$name<br />";


/*$sql ="SELECT * FROM `menu_items` WHERE `menuid`='$menuid'";
$result = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_array($result))
  {
  $name = $row['name'];
  echo $name . "<br />";
  }*/
  
  
  }
?>

 

Please help if you can. This is really frustrating.

 

Thanks heaps,

Sam.

 

Link to comment
https://forums.phpfreaks.com/topic/88965-solved-db-help-please/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.