Re: multi-dimentional array from db results
| From: | Jason Barnett | Date: | Tue, 30 Mar 2004 19:40:49 +0000 |
| Subject: | Re: multi-dimentional array from db results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181859@lists.php.net to get a copy of this message | ||
Motorpsychkill wrote:
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