Hi,
I need to know how to duplicate query results using MySQL/PHP. The simple approach of just copying the result variable does NOT work:
$result = mysql_query("SELECT ...");
$resultcopy = $result;
while ($row = mysql_fetch_array($result)) { ... }
while ($row = mysql_fetch_array($resultcopy)) { ... }
With this approach, the first while will work as intended. However, the second while (upon the copy) appears to be using an empty result. For testing purposes, I even copy+pasted the same code within the first while to the second while (so if it worked, I would see duplicate sets of outputs).
My guess is this approach does not work because $resultcopy = $result; is simply copying the resource id, instead of duplicating the resource. So, is there a way to actually duplicate the query result resource?
As it is, I'm having to redo the same exact query before each while. This is a bit taxing since it's a complex query on 200 x 20,000 rows generally producing a 10 row result. It would be much more efficient if I could simply duplicate the 10 row result for later use. =/
I've tried searching the manual, but nothing seems to cover this. Please help. Thanks.