RE: [PHP] Re: multi-dimentional array from db results
| From: | motorpsychkill | Date: | Tue, 30 Mar 2004 19:46:25 +0000 |
| Subject: | RE: [PHP] Re: multi-dimentional array from db results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181860@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jason Barnett [mailto:jasbarne@indiana.edu]
> Sent: Tuesday, March 30, 2004 11:41 AM
> To: php-general@lists.php.net
> Subject: [PHP] Re: multi-dimentional array from db results
>
>
> 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']);
>
Thanks dude, I've wasted a couple of hours on that :)
-m