Jump to content

Recommended Posts

I have the most simple loop ever on this earth an its doin strange things.  There are 6 rows in my cache table.  I have a query to echo the rows onto the page with a loop.  Now Im try to limit the rows returned to 1 row. simples eh.

 

 

$FetchCacheq = mysql_query("SELECT * FROM cacheInfo LIMIT 1") or die('cache error');





<table width="480" border="0" cellpadding="0" cellspacing="5">
          <tr>
            <td colspan="2" valign="baseline"><strong>Caches you have found</strong></td>
          </tr>
         <?php do { ?>
          <tr>
            <td width="250" height="31" align="left" valign="middle"><?php echo $row['cacheName'];?></td>
            <td width="230" align="left" valign="middle"><img src="/images/submit.png" width="20" height="20" /></td>
          </tr> 
	  <?php } while($row = mysql_fetch_assoc($FetchCacheq));?>
        </table>

 

The problem I have is its showing two rows.  Here is the source code from the page

 

 

<table width="480" border="0" cellpadding="0" cellspacing="5">
          <tr>
            <td colspan="2" valign="baseline"><strong>Caches you have found</strong></td>
          </tr>
                   <tr>
            <td width="250" height="31" align="left" valign="middle"></td>
            <td width="230" align="left" valign="middle"><img src="/images/submit.png" width="20" height="20" /></td>
          </tr> 
	            <tr>
            <td width="250" height="31" align="left" valign="middle">Your Life in Their Hands</td>
            <td width="230" align="left" valign="middle"><img src="/images/submit.png" width="20" height="20" /></td>
          </tr> 
	          </table>

as you can see one of the rows doesnt even have the cache name in it!!!

 

please help im really confused.

Link to comment
https://forums.phpfreaks.com/topic/259878-strange-looping-error/
Share on other sites

do{}while() loops are almost never used because they require extra logic (which you don't have in your code) to set up the data before the start of the loop.

 

For looping over database query results, where you don't expect exactly one row, you should always use a while(){} loop.

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.