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
Share on other sites

[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..
Link to comment
Share on other sites

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. 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.