andrew_ww Posted February 6, 2007 Share Posted February 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
only one Posted February 6, 2007 Share Posted February 6, 2007 <?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 Quote Link to comment Share on other sites More sharing options...
andrew_ww Posted February 6, 2007 Author Share Posted February 6, 2007 Thanks for suggestion. I tried the extra '=' signs however it now displays no records. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
andrew_ww Posted February 6, 2007 Author Share Posted February 6, 2007 This displays one date, and below that its echo'ed the value 0 Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 how much should it display? and please post the query, $rs_history please. Quote Link to comment Share on other sites More sharing options...
andrew_ww Posted February 6, 2007 Author Share Posted February 6, 2007 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); Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 try this: $i = 0; while($r = mysql_fetch_array($rs_history)){ echo $i."<br>"; $i++; } and see how much it is outputting. should print 0 and 1. Quote Link to comment Share on other sites More sharing options...
andrew_ww Posted February 6, 2007 Author Share Posted February 6, 2007 Nope all I get is 0. If I add another record (making a total of 3) then it ouputs 0 1 So its always missing off the last record. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 6, 2007 Share Posted February 6, 2007 that is very very odd. delete everything from your database. truncate it. remove it all and try again. Quote Link to comment Share on other sites More sharing options...
andrew_ww Posted February 6, 2007 Author Share Posted February 6, 2007 I changed it the Dreamweaver standard repeat region, and now it works: <?php do { ?> <?php echo $row_rs_test_issue['history_issue']; ?></br> <?php } while ($row_rs_test_issue = mysql_fetch_assoc($rs_test_issue)); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.