Jump to content

mysql_fetch_array, extracting variables


complex05

Recommended Posts

hello,

I've seen a function before that does this but forgot what it was. Right now whenever I use $data = mysql_fetch_array($query) i do the following after:

$name = $data["name"];
$email = $data["email"];
$phone = $data["phone"];

etc etc etc... isn't there a function that will do all of this for me?
Link to comment
https://forums.phpfreaks.com/topic/24117-mysql_fetch_array-extracting-variables/
Share on other sites

If you use the function mysql_fetch_assoc() instead, you can then use the [url=http://www.php.net/]extract()[/url] function to do that.  Why don't you just use the array references, which makes the code much more self-commenting.

Ken
[quote author=kenrbnsn link=topic=111674.msg452711#msg452711 date=1161020142]
If you use the function mysql_fetch_assoc() instead, you can then use the [url=http://www.php.net/]extract()[/url] function to do that.  Why don't you just use the array references, which makes the code much more self-commenting.

Ken
[/quote]

I've always wondered how people came to use mysql_fetch_array() instead of mysql_fetch_assoc(), seems like everyone does it..
i use fetch_array, simply because it's all encompassing. I mean, fetch_assoc returns an associative array.  fetch_row returns a numerical array.  but fetch_array returns both by default.  Or i can specify one or the other if i [i]really[/i] want to, with an optional argument.  But i usually don't.  I can simply use fetch_array and just use the numerical or associative version as i see fit.  I feel it is less hassle.  Maybe that's just me. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.