note 62394 deleted from function.mysql-fetch-field by bjori
| From: | bjori@php.net | Date: | Tue, 01 Aug 2006 09:04:57 +0000 |
| Subject: | note 62394 deleted from function.mysql-fetch-field by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115403@lists.php.net to get a copy of this message | ||
Note Submitter: jordan dot ledoux at gmail dot com
----
Here's a function which compiles an array out of a mysql query for any number of columns using
this function:
<?
function compile_array($mysql) {
$i = 0;
while ($field = mysql_fetch_field($mysql)) {
/* Create an array $fields which contains all of the column names */
$fields[$i] = $field->name;
$i++;
}
$i = 0;
while ($mysql_result = mysql_fetch_array($mysql)) {
foreach ($fields as $val) {
/* Compiles an array in the format:
$data [ row number ] [ column name ] */
$data[$i][$val] = $mysql_result[$val];
}
$i++;
}
return $data;
}
?>