Jump to content

reuse DO WHILE


dlf1987

Recommended Posts

I want to use the same query 2x on the same page.. I tried this...

 

<?php 
do {
     echo $row_rsTracking['track_id'];
} while ($row_rsTracking = mysql_fetch_assoc($rsTracking)); 
mysql_data_seek($rsTracking, 0); //Reset
?>

RESULTS:
Line1
Line2

<?php 
do {
     echo $row_rsTracking['track_id'];
} while ($row_rsTracking = mysql_fetch_assoc($rsTracking)); 
?>

RESULTS:
[blank line]
Line1
Line2

 

Why is there an extra line showing up for the 2nd do while?

 

Link to comment
https://forums.phpfreaks.com/topic/118510-reuse-do-while/
Share on other sites

Because you are using a DO WHILE which evaluates the condition after executing the code. $row_rsTracking probably doesn't exist at the first loop, but maybe you have error reporting off. At the second loop, $row_rsTracking was set to null from the previous conditional operation. It should work if you use a regular while loop instead.

Link to comment
https://forums.phpfreaks.com/topic/118510-reuse-do-while/#findComment-610123
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.