note 4235 deleted from ref.mysql by aidan
| From: | aidan@php.net | Date: | Sun, 15 Aug 2004 11:08:12 +0000 |
| Subject: | note 4235 deleted from ref.mysql by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74691@lists.php.net to get a copy of this message | ||
Note Submitter: steer at projex dot hu
----
A quick way to extract a mysql query result into variables, without using an array:
$result = mysql_query("select model,color,price from cars where id=$id");
extract(mysql_fetch_assoc($result));
Now you have the variables $model, $color, $price. You can ask extract() to prefix it for you, with
like extract(stuff,EXTR_PREFIX_ALL,"r"), and right there you have $r_model, $r_color...
If you have to pull multiple rows from the query, e.g. using "while", you have to pull
'em to an array, but still can use extract() to extract them :)
while ($r = mysql_fetch_array($result)) {
extract($r);
...
}