We help IT Professionals succeed at work.

Problem with while loop?

andyw27
andyw27 asked
on
254 Views
Last Modified: 2008-02-01

I have a while loop that enables me to see all the records that a table contains, thr trouble is its not displaying the very lats record.  If I changed it a do loop it will display a blank record if no other exists.  Does anything look out of place with with code ?

<?php while ($row_rs_history = mysql_fetch_assoc($rs_history)) { ?>
<table width="450" align="center" cellpadding="1" cellspacing="1">
  <tr>
    <td width="50%"><div align="left"><?php echo $row_rs_history['issue']; ?></div></td>
    <td width="50%"><?php echo strftime('%d %B %Y', strtotime($row_rs_history['update_date'])); ?></td>
  </tr>
  <tr>
    <td colspan="2"><div align="left"></div>
      <div align="left"></div>      <div align="left">
        <hr />
      </div></td>
  </tr>
</table>
<?php } ?>
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
The problem with a foreach is you have to already have the values in an array, whereas in andyw27's case each row is read individually from mysql_fetch_assoc().  

Nothing looks wrong with that code to me.  How can you tell there's a row there that's not getting returned?  Are you certain the underlying query doesn't just miss that one?

Author

Commented:
I've put the query string into MySQL Query Browser and it returns the correct number of results.

It's only when the query is run within the php page that I encounter problems.

I've placed the following code on to the page and this shows the correct number of results:

<?php echo $totalRows_rs_history; ?>
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.