Passing database values into an array

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
welsh_sponger
Forum Newbie
Posts: 14
Joined: Fri Feb 03, 2006 7:46 am

Passing database values into an array

Post 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
ody
Forum Contributor
Posts: 147
Joined: Sat Mar 27, 2004 4:42 am
Location: ManchesterUK

Post by ody »

mysql_fetch_array() ?
welsh_sponger
Forum Newbie
Posts: 14
Joined: Fri Feb 03, 2006 7:46 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A posted solution to another, exactly similar question I posted:

viewtopic.php?p=245500#245500
Post Reply