RE: [PHP] array

From: Date: Mon, 12 Mar 2001 21:27:10 +0000
Subject: RE: [PHP] array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-43560@lists.php.net to get a copy of this message
> Hello!!! > > Please, assume I have the following mysql query: > > function get_products() { > > $result = mysql_query("select * from products"); > while ($row = mysql_fetch_array($result)) { > $prod_id = $row["prod_id"]; > $prod_name = $row["prod_name"']; > $prod_price = $row["prod_price"]; > } > return $products; > } > > The question: > > Ok, my $products variable will be an array with all products ??? No, it won't be. Rewrite the function like this: function get_products() { $result = mysql_query("select * from products"); $i = 0; while ($row = mysql_fetch_array($result)) { $products[$i]["prod_id"] = $row["prod_id"]; $products[$i]["prod_name"] = $row["prod_name"']; $products[$i]["prod_price"] = $row["prod_price"]; $i++; } return($products); } That will return a double scripted array of all the products information. - James http://www.phpbb.com

« previous php.general (#43560) next »