note 4235 modified in ref.mysql by philip
| From: | philip@php.net | Date: | Tue, 16 Jul 2002 16:02:20 +0000 |
| Subject: | note 4235 modified in ref.mysql by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-33142@lists.php.net to get a copy of this message | ||
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);
...
}
--was--
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_array($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);
...
}
That was it, maybe it'll help someone..
http://www.php.net/manual/en/ref.mysql.php