note 46458 added to function.mysql-fetch-row
| From: | girish dot sonawane at gmail dot com | Date: | Tue, 12 Oct 2004 12:50:25 +0000 |
| Subject: | note 46458 added to function.mysql-fetch-row | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78404@lists.php.net to get a copy of this message | ||
Here's a modified version of Jame's set_variables_after_query()
The modified version returns an array of hashes containing all the records...
function set_array_from_query($qry) {
$arr = array();
$selection = mysql_query($qry);
if (!$selection) {
die('Invalid query: ' . mysql_error());
}
if (mysql_num_rows($selection) > 0)
{
$x=0;
// iterate through resultset
while($row = mysql_fetch_row($selection))
{
foreach($row as $i => $value) {
$column = mysql_field_name($selection,$i);
$data["$column"] = $value;
$arr[$x] = $data;
}
$x++;
}
}
return $arr;
}
//Examples
$array = set_array_from_query("select * from SomeTable");
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-row.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46458
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46458&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46458&report=yes
Search -- http://master.php.net/manage/user-notes.php