DVigneault Posted August 2, 2011 Share Posted August 2, 2011 Hey all-- Here's the setup: I'm joining two tables and then using while($row = mysql_fetch_array($result)) to echo the resulting records into an HTML table. But only 15 of the 16 records are showing up. If I delete one record, I get 14 out of 15. The one to not show up is always the latest record. <?php if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("atsband", $con); $query = "SELECT some fields of table 1 and table 2 FROM table 1 LEFT JOIN table 2 ON table 1.field = table 2.field WHERE date < NOW() ORDER BY date DESC"; if ($result = mysql_query($query, $con)) { if (mysql_num_rows($result)) { while($row = mysql_fetch_array($result)) { echo "<table id='shows_past'><th>Date/Time</th><th>Venue</th><th>Location</th>"; while($row = mysql_fetch_array($result)) { echo "an HTML table"; } echo "</table>"; } } else { echo "Something went wrong."; } } else { echo "The query failed."; } mysql_close($con); ?> There's a similar question posted here, but I couldn't figure out if we were doing the same thing wrong (very new to MySQL and PHP by the way): http://www.phpfreaks.com/forums/index.php?topic=325757.msg1534001#msg1534001. Thanks a bunch, -Davis Quote Link to comment https://forums.phpfreaks.com/topic/243627-whilerow-mysql_fetch_arrayresult-isnt-returning-final-record/ Share on other sites More sharing options...
DVigneault Posted August 2, 2011 Author Share Posted August 2, 2011 Oh and I'm using MySQL version 5.0 and PHP version 5.2 (on a godaddy account). Quote Link to comment https://forums.phpfreaks.com/topic/243627-whilerow-mysql_fetch_arrayresult-isnt-returning-final-record/#findComment-1250855 Share on other sites More sharing options...
requinix Posted August 2, 2011 Share Posted August 2, 2011 It's not returning the first record. The last one is there. You have two while loops. The earlier one doesn't belong and is causing the problem. Quote Link to comment https://forums.phpfreaks.com/topic/243627-whilerow-mysql_fetch_arrayresult-isnt-returning-final-record/#findComment-1250870 Share on other sites More sharing options...
DVigneault Posted August 2, 2011 Author Share Posted August 2, 2011 Thanks! That fixed it. :-) Quote Link to comment https://forums.phpfreaks.com/topic/243627-whilerow-mysql_fetch_arrayresult-isnt-returning-final-record/#findComment-1250909 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.