cedricganon Posted November 8, 2011 Share Posted November 8, 2011 Hello Everyone So i have this script that pulls some stuff out of a db and displays it. Pretty basic. It used to work fine but now it omits one entry from the table. It always shows one less than its supposed to. I.E. if there are 4 table entries, it only shows 3. It didnt do this before and I'm not sure why it changed. I didnt edit the code at all. Here it is: else{ $sql = "SELECT * FROM article WHERE lang='" . $validlang ."' AND cat_id=" . $validentry . " ORDER BY id DESC LIMIT 5"; $result = mysql_query($sql); if(!$result){ echo "Error querying the database." . mysql_error(); exit; } else{ $row = mysql_fetch_assoc($result); } if(!$row){ echo "Error: No articles found." . mysql_error(); exit; } else{ echo "<div id='section'>Organization News</div>"; while($row = mysql_fetch_assoc($result)){ echo "<h3><a href='" . $validlang . "/" . $row['location'] . "'>" . $row['title'] . "</a></h3>"; echo "<div id='subtitle'>" . $row['summary'] . "</div>"; } } } Any help would be appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/250669-mysql-request-suddenly-not-working-properly/ Share on other sites More sharing options...
trq Posted November 8, 2011 Share Posted November 8, 2011 Your calling mysql_fetch_assoc() once outside of the while loop. Why? You never use the row it returns. This code would have always worked this way. Link to comment https://forums.phpfreaks.com/topic/250669-mysql-request-suddenly-not-working-properly/#findComment-1286097 Share on other sites More sharing options...
cedricganon Posted November 8, 2011 Author Share Posted November 8, 2011 *facepalm*. Thank you Link to comment https://forums.phpfreaks.com/topic/250669-mysql-request-suddenly-not-working-properly/#findComment-1286101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.