Jump to content

Problem with While loop


andrew_ww

Recommended Posts

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 } ?>

 

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; ?>

 

Thanks.

Link to comment
Share on other sites

<?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 } ?>

 

try it with 2 = signs

Link to comment
Share on other sites

only one. that isnt really the answer, because you want to set $row_rs_history to equal (using one = sign) the array.

 

run in like this:

 

<?php $i = 0; 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 echo $i."<br>"; $i++; } ?>

 

and tell me how much times its being outputted to how much times it should be outputted.

Link to comment
Share on other sites

 

I should be displaying two records:

 

$query_rs_history = sprintf("SELECT * FROM tbl_history WHERE site_id = %s ORDER BY history_id DESC", $colname_rs_history);
$rs_history = mysql_query($query_rs_history, $DII) or die(mysql_error());
$row_rs_history = mysql_fetch_assoc($rs_history);
$totalRows_rs_history = mysql_num_rows($rs_history);

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.