note 87201 added to function.mysql-fetch-array
| From: | KingIsulgard at osu1 dot php dot net | Date: | Mon, 24 Nov 2008 13:49:12 +0000 |
| Subject: | note 87201 added to function.mysql-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146869@lists.php.net to get a copy of this message | ||
I have found a way to put all results from the select query in an array in one line.
// Read records
$result = mysql_query("SELECT * FROM table;") or die(mysql_error());
// Put them in array
for($i = 0; $array[$i] = mysql_fetch_assoc($result); $i++) ;
// Delete last empty one
array_pop($array);
You need to delete the last one because this will always be empty.
By this you can easily read the entire table to an array and preserve the keys of the table columns.
Very handy.
----
Server IP: 193.190.67.7
Probable Submitter: 84.192.161.187
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php
Edit -- https://master.php.net/note/edit/87201
Del: integrated -- https://master.php.net/note/delete/87201/integrated
Del: useless -- https://master.php.net/note/delete/87201/useless
Del: bad code -- https://master.php.net/note/delete/87201/bad+code
Del: spam -- https://master.php.net/note/delete/87201/spam
Del: non-english -- https://master.php.net/note/delete/87201/non-english
Del: in docs -- https://master.php.net/note/delete/87201/in+docs
Del: other reasons-- https://master.php.net/note/delete/87201
Reject -- https://master.php.net/note/reject/87201
Search -- https://master.php.net/manage/user-notes.php