Can you reuse a mysql result set in PHP?

Posted by MarathonStudios on Stack Overflow See other posts from Stack Overflow or by MarathonStudios
Published on 2011-01-09T06:42:37Z Indexed on 2011/01/09 6:53 UTC
Read the original article Hit count: 221

Filed under:
|
|

I have a result set I pull from a large database:

$result = mysql_query($sql);

I loop through this recordset once to pull specific bits of data and get averages using while($row = mysql_fetch_array($result)). Later in the page, I want to loop through this same recordset again and output everything - but because I used the recordset earlier, my second loop returns nothing.

I finally hacked around this by looping through a second identical recordset ($result2 = mysql_query($sql);), but I hate to make the same SQL call twice. Any way I can loop through the same dataset multiple times?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql