View Full Version : PHP MySQL column value for row

02-23-2010, 10:35 AM
Ok, so what I need to do is use MySQL in PHP to get a column value from a row. Currently I'm using the following code:

$query = mysql_query("SELECT blah FROM table WHERE blah = 'blah'");
$result = mysql_fetch_array($query);
$result = $result["blah"];

And I have to do that because the query returns an array that is the same as what SELECT * FROM would return. Why wont it just return the column value I want? What do I have to do to make this happen?

Ehhh.... Human error, it was returning the correct array. Sorry guys.

02-23-2010, 04:05 PM
I noticed that you don't show which type of array you're wanting returned.

Also, if there's more than one matching result set use the following:

$query = mysql_query("SELECT blah FROM table WHERE blah = 'blah';");

while($result = mysql_fetch_array($query, MYSQL_ASSOC))
print $result["blah"] . "<br />\n";
mysql_free($result); # free the result :)