does mysql_ fetch_array have a single friend?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

does mysql_ fetch_array have a single friend?

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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:
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Either way is fine
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

:arrow: Moved to PHP Code.
Post Reply