"Alex Hogan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I have asked a lot of questions in the last few weeks, but I do try to
> preface those questions by checking out the php.net online manual first.
>
> Anyway, here is one way to do it.  There are probably more elegant
> solutions, but I don't know off hand what they are.
>
> $model  = array();
>
> $query  = "SELECT product_id
>     FROM products";
> $result = mysql_query($query) or die("error in query);
> $i      = 0;
> while($row = mysql_fetch_array($result)){
> $model[$i] = $row['product_id'];
> $i++;
> }

I think $i is not needed here. If you add it to the array with $model[] =
... PHP will automatically use and increment an integer for the key.

Regards, Torsten

>
> print_r($model);
>
>
>
>
> alex hogan
>
>
> > -----Original Message-----
> > From: Phpu [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, April 28, 2004 3:01 PM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] Listing all id's in array
> >
> > I want to list all the product id's af the database in an array, but i
do
> > not how.
> >
> > I have this script but it is not working:
> >
> > $model = array();
> >
> > $query = "SELECT product_id FROM products";
> > $result = mysql_query($query) or die("error in query - $query -
> > ".mysql_error());
> > while (list($product_id) = mysql_fetch_array($result)) {
> > $model = "$product_id";
> > }
> >
> > echo "$model";
> >
> >
> > Plese someone tell me how to do it...
> >
> > Thanks
>
>
>
> ******************************************************************
> The contents of this e-mail and any files transmitted with it are
> confidential and intended solely for the use of the individual or
> entity to whom it is addressed.  The views stated herein do not
> necessarily represent the view of the company.  If you are not the
> intended recipient of this e-mail you may not copy, forward,
> disclose, or otherwise use it or any part of it in any form
> whatsoever.  If you have received this e-mail in error please
> e-mail the sender.
> ******************************************************************
>
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to