Re: Listing all id's in array

From: Date: Thu, 29 Apr 2004 17:52:51 +0000
Subject: Re: Listing all id's in array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-184967@lists.php.net to get a copy of this message
"Alex Hogan" <Alex.Hogan@AlliedElec.com> wrote in message news:F63DEC4D37ACD41183C700508B95574F0F88D1E0@exchsrvr.alliedelec.com... > 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: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. > ****************************************************************** > > >

« previous php.general (#184967) next »