Fastest loop code/best way to get database results into array
| From: | Galen | Date: | Mon, 01 Dec 2003 08:06:34 +0000 |
| Subject: | Fastest loop code/best way to get database results into array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-171442@lists.php.net to get a copy of this message | ||
I'm working on some code that deals with a LOT of results from a MySQL database and drops them into an array. It deals with about 17,200 results on a very fast box in about 0.5 seconds, which is not too bad, until I realize I may need to call it on about that many results several times in a page.
Is there any way to speed things up? Change to a different loop type? Some other technique for pulling the data out of the database faster? My only requirement is that the array format remain unchanged (yes, associative values are important).
Here's the code, which seems awfully simple:
for($i=0; $i < $num_results; $i++)
{
$search_results[$i] = mysql_fetch_array($result, MYSQL_ASSOC);
}