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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.