For whatever reason, I need to go through a MySQL result set twice. Is there a way to do it?
I don't want to run the query twice and I don't want to have to rewrite the script so that it stores the rows somewhere and then reuses them later.
The mysql_result() function returns the value of a field in a recordset. This function returns the field value on success, or FALSE on failure.
The WHERE Clause is used to filter only those records that are fulfilled by a specific condition given by the user. in other words, the SQL WHERE clause is used to restrict the number of rows affected by a SELECT, UPDATE or DELETE query.
The WHERE clause is used to filter records. The WHERE clause is used to extract only those records that fulfill a specified condition. SELECT column_name(s) FROM table_name WHERE column_name operator value. To learn more about SQL, please visit our SQL tutorial.
This is how you can do it:
$result = mysql_query(/* Your query */); while($row = mysql_fetch_assoc($result)){ // do whatever here... } // set the pointer back to the beginning mysql_data_seek($result, 0); while($row = mysql_fetch_assoc($result)){ // do whatever here... }
However, I would have to say, this doesn't seem the right way to handle this. Why not do the processing within the first loop?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With