RE: [PHP] Listing all id's in array
| From: | Alex Hogan | Date: | Wed, 28 Apr 2004 20:17:46 +0000 |
| Subject: | RE: [PHP] Listing all id's in array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-184901@lists.php.net to get a copy of this message | ||
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++;
}
print_r($model);
alex hogan
> -----Original Message-----
> From: Phpu [mailto:phpu@go.ro]
> Sent: Wednesday, April 28, 2004 3:01 PM
> To: php-general@lists.php.net
> 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.
******************************************************************