TGWSE_GY Posted August 26, 2009 Share Posted August 26, 2009 Ok guys this one is a strange one. I know that this is not a mysql issue because mysql is not outputting any errors. I believe it is in the while loop, however I have never seen a while loop act like this. here is a link to the page http://www.jamsmagazine.com/index2.php?section=news and here is my code <p><img src="images/jams-magazine-news.gif" width="150" height="20"></p> <?php //Get database connectiong config include('config.php'); $query = "SELECT * FROM jamsmag_news ORDER BY id ASC LIMIT 4"; $result = mysql_query($query) or die(mysql_error()); //Get article from db $count = "0"; while ($row = mysql_fetch_assoc($result) or die(mysql_error())) { $title = $row['title']; $article = $row['article']; echo $title; echo $article; echo $count; $count = $count + 1; } ?> Now it is repeating the second news article "No more Gorillaz studio albums" is being repeated. whats more the first article is not displaying the counter echoed. What is causing this odd behavior any ideas, there are only 4 records in the news table so this makes no sense. Thanks :facewall: :facewall: Quote Link to comment https://forums.phpfreaks.com/topic/172006-extra-itteration-through-loop/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2009 Share Posted August 26, 2009 Remove the or die(...) from the end of the mysql_fetch_assoc(). That makes no sense for a couple of reasons. msyql_fetch_assoc() does not produce a mysql error, it fetches rows from the result set and when there are no more rows in the result set a FALSE is returned so your code will die() at that point with nothing being output following your loop. For any other problems, you should directly examine the data in your table because it is probably not what you think it is. Quote Link to comment https://forums.phpfreaks.com/topic/172006-extra-itteration-through-loop/#findComment-906959 Share on other sites More sharing options...
TGWSE_GY Posted August 26, 2009 Author Share Posted August 26, 2009 Ok removed the or die, and I have checked, checked again, and rechecked again and the data is in the data base is absolutly correct. so why is the second record being repeated? I am absolutely sure that it is all right. Quote Link to comment https://forums.phpfreaks.com/topic/172006-extra-itteration-through-loop/#findComment-907044 Share on other sites More sharing options...
mikesta707 Posted August 26, 2009 Share Posted August 26, 2009 well if you are going to preform math on count, you want to it be an integer, not a string (which it currently is) so change $count = "0"; to $count = 0; you can also change $count = $count + 1; to $count++; its a little easier but i doubt that has anything to do with your error Quote Link to comment https://forums.phpfreaks.com/topic/172006-extra-itteration-through-loop/#findComment-907047 Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2009 Share Posted August 26, 2009 Cannot really help you without seeing the results you are getting and seeing the results you expect along with seeing what the actual data in the table is. Quote Link to comment https://forums.phpfreaks.com/topic/172006-extra-itteration-through-loop/#findComment-907055 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.