Jump to content

[SOLVED] Help with displaying Array


dfowler

Recommended Posts

I'm working on a restaurants website.  I've set it up where a customer can come online and order items off their menu.  I have then tried to create an administrator side where they can view these orders.  Here is where the problem is.  The display currently looks like this:

 

Order ID

Contact Info

Order

Specials/Instructions

Date/Time to Fill

41

Test User, [email protected], 9125555555

Fried Fish Submarine with fries

Caesar Salad

Aug 31,2007 11:45

 

Looks great, however, the customer ordered more than just a fish submarine.  The tables are set up as follows:

 

Orders

Order_Items

Items

ID

ID

ID

Cus_Name

Order_ID

Item_Name

Cus_Phone

Item_ID

Item_Price

Cus_Email

Quantity

Order_Date

Specials

 

Here is the code I am using to display the items:

$resource = myQuery("select * from ".ORDERSTABLE." where active='y' and for_date <= NOW() order by for_date");
$nowOrders = array();
while (($row = mysql_fetch_assoc($resource)) !== false) {
  $nowOrders[] = $row;
}

$itemid = array();
foreach ($nowOrders as $o) {
$resource = myQuery("select * from ".OLINKTABLE." where order_id=".$o['id']."");
	while (($row = mysql_fetch_assoc($resource)) !== false) {
	$itemid[$o['id']] = $row;
}
}

$items = array();
foreach ($itemid as $o) {
$resource = myQuery("select * from ".ITEMSTABLE." where id=".$o['item_id']."");
while (($row = mysql_fetch_assoc($resource)) !== false) {
  		$items[$o['order_id']] = $row;
}
}

<?php
foreach ($nowOrders as $o) {
?>
    <td><?php echo $o['id']; ?></td>
    <td><?php echo $o['name'].', '.$o['email'].', '.$o['phone']; ?></td>
<td><?php echo $items[$o['id']]['name']; ?></td>
<td><?php echo $o['instructions']; ?></td>
    <td><?php echo $date = date("M d,Y g:i", strtotime($o['for_date']));; ?></td>
    <td><input type="checkbox" name="inactive[]" value="<?php echo $o['id']; ?>"/></td>
  </tr>
<?php
}
?>

 

Can anybody see what I am doing wrong?  I can figure out why it is only displaying one order (even though in the table on the database side it shows multiple items under the Order_ID).  I feel like it is something small as I am very close.  I hope somebody can help with this.

Link to comment
https://forums.phpfreaks.com/topic/68056-solved-help-with-displaying-array/
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.