Page 1 of 1

Passing database values into an array

Posted: Sun Mar 12, 2006 6:34 am
by welsh_sponger
I would like to run a query on a databse and then pass the values into an array...

Ive written the code to get the values i need:

Code: Select all

$firstquery = "SELECT this
		FROM thatTable" or die ("Unable to...");
		$result = mysql_query($firstquery, $dblink);
			$num=mysql_numrows($result);
				$i=0;
				while ($i < $num) {
					$values = mysql_result($result,$i,"valuesiwant");
						$i++;
						}
mysql_close();
which i can use to print out all the results. I want to put the results into an array now, but not sure how to do so.

Please help!

Thanks

Posted: Sun Mar 12, 2006 6:50 am
by ody
mysql_fetch_array() ?

Posted: Sun Mar 12, 2006 9:22 am
by welsh_sponger
Yes thats works correctly, however...

It puts the values that i need into the same part of the array...

Im retrieving values from the same column so this function puts them all into the first position in the array.
I want them to go into seperate positions for each value from the column...

Code: Select all

$query = mysql_db_query ("database", "SELECT this
			FROM thatTab") or die ("Unable to...");


		while ($row = mysql_fetch_array($query)) {
How can i change this so that it puts each value into a different position in the array?

Thanks

Posted: Sun Mar 12, 2006 9:28 am
by feyd
A posted solution to another, exactly similar question I posted:

viewtopic.php?p=245500#245500