I'm trying to re-create the following multi-dimentional array from a database query, where the indices 5, 7 and 21 are "order_id" and my table is
food_orders(order_id, food, cooked):
<?php $food_array = array( 5=>array('steak','rare'), 7=>array('burger','medium'), 21=>array('lamb_chops','well'), );
$query = "select * from food_orders where date = NOW()"; $result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$food_array[$row['order_id']] .= array($row['food'], $row['cooked']);
The .= operator is for concatenating strings. The above code block adds the result of array($row['food'], $row['cooked']) to a blank string. If you are trying to assign array variables you want to use
$food_array[$row['order_id']] = array($row['food'], $row['cooked']);
}
?>
This looks fine to me, but when I do a:
print_r($food_array)
All I get is
Array ( [5] => Array [7] => Array [21] => Array )
That is, I don't see the output of each order. Any suggestions would be greatly appreciated!
-m
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php