note 102057 deleted from function.mysql-fetch-array by danbrown
| From: | danbrown@php.net | Date: | Tue, 25 Jan 2011 13:52:10 +0000 |
| Subject: | note 102057 deleted from function.mysql-fetch-array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176286@lists.php.net to get a copy of this message | ||
Note Submitter: Paul S
----
> Sebastian K 02-Mar-2010 08:56
> To put the full result in one array, I wrote this function:
Hi Sebastian, you can have it without the inner loop:
<?php
$query = "select * from table_xyz";
$result = mysql_query($query) or die(mysql_error());
$arr_table_result = mysql_fetch_full_result_array($result);
echo $arr_table_result[2]['id'];
function mysql_fetch_full_result_array($result)
{
$table_result=array();
$r=0;
while($row = mysql_fetch_assoc($result, MYSQL_ASSOC)){
$table_result[$r++] = $row;
}
return $table_result;
}
?>
> <?php
> $query="select * from table_xyz";
> $result = mysql_query($query) or die(mysql_error());
> $arr_table_result=mysql_fetch_full_result_array($result);
>
> function mysql_fetch_full_result_array($result)
> {
> $table_result=array();
> $r=0;
> while($row = mysql_fetch_assoc($result)){
> $arr_row=array();
> $c=0;
> while ($c < mysql_num_fields($result)) {
> $col = mysql_fetch_field($result, $c);
> $arr_row[$col -> name] = $row[$col -> name];
> $c++;
> }
> $table_result[$r] = $arr_row;
> $r++;
> }
> return $table_result;
> }
>
> echo $arr_table_result[2]['id'];
> ?>