Page 1 of 1

does mysql_ fetch_array have a single friend?

Posted: Wed Sep 19, 2007 2:36 pm
by lafflin
Hello, I am just wondering is it a problem to use mysql_fetch array when i know that I'm going to be pulling out just one row?
mysql_fetch_row gives back an indexed array which isn't sexy.
is there another function I should learn or is mysql_ fetch_array the way to go when just wanting one row as an associative array?

Posted: Wed Sep 19, 2007 3:43 pm
by John Cartwright

Code: Select all

$result = mysql_query($sql) or die(mysql_error());

$row = mysql_fetch_assoc($result);

echo '<pre>';
print_r($row);
:wink:

Posted: Wed Sep 19, 2007 4:09 pm
by lafflin
would that be the same as

Code: Select all

mysql_fetch_array($result1, MYSQL_ASSOC)
?
ofcourse if it is, your way is a little less typing, I was just asking because I want to learn the right way of doing things.

Posted: Wed Sep 19, 2007 7:29 pm
by John Cartwright
Either way is fine

Posted: Thu Sep 20, 2007 6:00 am
by Chris Corbyn
:arrow: Moved to PHP Code.