Jump to content

[SOLVED] Assign each value from mysql query automatically?


scooter41

Recommended Posts

Hi There... is there anyway after retrieving a mysql query, I can automatically assign "all values with a respective variable name"?

 

Example:

 

instead of saying

 

$name=$row['name'];

$email=$row['email];

$username=$row['username'];

 

that I can just say ...

 

retrieve data query...

then for all row fields, assign to a respective variable name?

 

I'm moving from a perl/cgi land which it was relatively simple there, so assume it is here too :)

 

Thanks for any help in advance.

Link to comment
Share on other sites

No problem. Just fyi, the use of the double dollar sign means you are using a variable variable: the name of the variable you assign $v to is the value of the variable $k. Perhaps another example illustrates that better:

 

<?php
$foo = 'bar';
$bar = 'test';
echo $$foo; //is equivilant to echo $bar, since 'bar' is the value of $foo
//produces test
?>

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.