Reusing MySQL Result Sets with the mysql_* Functions
Question:
Is it possible to iterate through a MySQL result set multiple times using the mysql_* functions?
Background:
Sometimes, it may be necessary to process a MySQL result set twice without rerunning the query or storing its rows.
Answer:
Yes, it is possible. Here's how:
$result = mysql_query(/* Your query */); while ($row = mysql_fetch_assoc($result)) { // do whatever here... } // reset the result set pointer to the beginning mysql_data_seek($result, 0); while ($row = mysql_fetch_assoc($result)) { // do whatever here... }
Note:
While this method allows you to reuse the result set, it is generally not considered best practice. It is preferable to perform all necessary processing within the initial loop.
The above is the detailed content of Can I Iterate Through a MySQL Result Set Multiple Times Using the mysql_* Functions?. For more information, please follow other related articles on the PHP Chinese website!