note 102057 added to function.mysql-fetch-array
| From: | PaulS at osu1 dot php dot net | Date: | Tue, 25 Jan 2011 12:14:29 +0000 |
| Subject: | note 102057 added to function.mysql-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176284@lists.php.net to get a copy of this message | ||
> 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'];
> ?>
----
Server IP: 69.147.83.197
Probable Submitter: 81.2.148.66
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php
Edit -- https://master.php.net/note/edit/102057
Del: integrated -- https://master.php.net/note/delete/102057/integrated
Del: useless -- https://master.php.net/note/delete/102057/useless
Del: bad code -- https://master.php.net/note/delete/102057/bad+code
Del: spam -- https://master.php.net/note/delete/102057/spam
Del: non-english -- https://master.php.net/note/delete/102057/non-english
Del: in docs -- https://master.php.net/note/delete/102057/in+docs
Del: other reasons-- https://master.php.net/note/delete/102057
Reject -- https://master.php.net/note/reject/102057
Search -- https://master.php.net/manage/user-notes.php