unistake Posted July 20, 2010 Share Posted July 20, 2010 Hi all, I am trying to display all the rows in a mysql table i have. - 4 at the moment. The last 3 rows are showing no problem but the first one is not being displayed. The code I am using is $sql = "SELECT * FROM sales ORDER BY id DESC"; $result = mysqli_query($cxn,$sql) or die ("Cant execute query"); $num = mysqli_num_rows($result); $row = mysqli_fetch_assoc($result); $counter=1; echo "$num aircraft were found"; while ($row = mysqli_fetch_assoc($result)) { extract($row); echo "$id, $details<br>"; } Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/208317-missing-1st-row-of-a-mysql-table/ Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 You're fetching the first row here $num = mysqli_num_rows($result); $row = mysqli_fetch_assoc($result); // <---- but you do not echo it. Quote Link to comment https://forums.phpfreaks.com/topic/208317-missing-1st-row-of-a-mysql-table/#findComment-1088710 Share on other sites More sharing options...
PFMaBiSmAd Posted July 20, 2010 Share Posted July 20, 2010 Edit: Basically the same as above ^^^^ missing 1st row of a mysql table That's because your code is fetching and discarding the first row in the result set - $num = mysqli_num_rows($result); $row = mysqli_fetch_assoc($result); // ****** you are fetching and discarding this row ******* $counter=1; Why do you have that line in your code ^^^^^ Quote Link to comment https://forums.phpfreaks.com/topic/208317-missing-1st-row-of-a-mysql-table/#findComment-1088711 Share on other sites More sharing options...
unistake Posted July 20, 2010 Author Share Posted July 20, 2010 Thanks for both of your help, I had it as I have been copying PHP scripts! Thought it maybe needed here as I prefer to use mysql values as $var instead of $row[var]. Now that you said it, I can see its not needed! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/208317-missing-1st-row-of-a-mysql-table/#findComment-1088726 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.