chris
chris

Reputation: 21197

How to convert variables from MYSQL result into PHP variables with same name?

I am running this mysql query:

$result = mysql_query("SELECT * FROM  userdetails WHERE  userid= '$userid'");
$row = mysql_fetch_array($result);

The result is a row of 100 variables with different names such as $row['name'], and $row['email'], etc...

How can I convert all of these to just $name and $email, etc... in php?

It would save so much time to write this program....

Upvotes: 0

Views: 1015

Answers (3)

Matt
Matt

Reputation: 450

Short anwser: extract

long anwser : don't. It may seem like a good anwser now but if you use it much it will become a problem keeping track of stuff.

Upvotes: 4

Justin
Justin

Reputation: 5069

You probably don't ultimately want to do that, but the extract() function does this.

https://www.php.net/manual/en/function.extract.php

Upvotes: 3

fiskah
fiskah

Reputation: 5902

https://www.php.net/extract

Upvotes: 3

Related Questions