Return mysql_fetch_array($result) from a function

From: Date: Wed, 05 Nov 2003 06:53:15 +0000
Subject: Return mysql_fetch_array($result) from a function
Groups: php.general 
Request: Send a blank email to php-general+get-168533@lists.php.net to get a copy of this message
Hi All, I am trying to get the results of a function, which queries MySQL, back into an array for me to order. I only want to print out certain fields (I call the same query, but use different fields in different places). This works is I print out the fields in the function itself: while($row = mysql_fetch_array($result)) { echo $row["id"] . "<br>"; } This however prints out an unending list of values: /* This is where I think it's getting messed up, since it doesnt seem to be able to store the "query" in a variable. I suspect it's something to do recursive and multi-dimension arrays http://www.phpbuilder.com/manual/language.types.array.php*/ $mysql_query = mysql_fetch_array($result); while($row = $mysql_query) { echo $row["id"] . "<br>"; } Can someone perhaps show me how to do it (or point me in the right direction), since I need to do this: function ReturnSQLResults() { .................... $mysql_query = mysql_fetch_array($result); return $mysql_query; } And then be able to just print the fields I require. Thanks in advance!!! Terence

« previous php.general (#168533) next »