Hello All
I have a question concerning MySQL fetches. This is how I, and I assume most PHP developers, get MySQL Data:
$sql = "select * from table";
$results = mysql_query($sql);
while($rows = mysql_fetch_array($results)){
$value_01 = (isset($eventRows['value_01'])) ? $eventRows['value_01'] : null;
$value_02 = (isset($eventRows['value_02'])) ? $eventRows['value_02'] : null;
$value_03 = (isset($eventRows['value_03'])) ? $eventRows['value_03'] : null;
$value_04 = (isset($eventRows['value_04'])) ? $eventRows['value_04'] : null;
$value_05 = (isset($eventRows['value_05'])) ? $eventRows['value_05'] : null;
echo $value_01 . " - " . $value_02 . " - " . $value_03 . " - " . $value_04 . " - " . $value_05 . "<br>\n";
}
According to PHP.net, the "mysql_query" function "Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead."
What I was wondering is if you can store the returned results so that they can be used multiple times on the same page without having to make multiple database calls? I am designing a page where I need to us values 1-5 in one loop but only value 1 in another loop. Database calls are expensive so I would rather make the initial data fetch, and store the results for future use. Something like:
$storage_device = mysql_fetch_array($results);
As you can guess, or probably already know, that doesn't work.
Thank you all for reading. Have a nice day/night.
