bravo14 Posted January 22, 2014 Share Posted January 22, 2014 Hi Guys Hope someone can help me. I have some code that runs a query and finds 3 rows for example, however only 2 are displayed on the page, however many records are found on the query it will always show 1 less. I have attached the page productList.php Quote Link to comment https://forums.phpfreaks.com/topic/285579-not-all-records-are-being-displayed/ Share on other sites More sharing options...
Ch0cu3r Posted January 22, 2014 Share Posted January 22, 2014 (edited) Because on line 30 you are calling mysql_fetch_assoc, which will pull the first result from the query. Then on line 38 for the while loop condition you are calling dbFetchAssoc(), which is a user defined defined function and is probabcalling mysql_fetch_assoc internally, which will then loop over the remaining results from the query. Now each time mysql_fetch_assoc is called it increments the internal row counter by 1. When this happens the next row is returned from the result the next time mysql_fetch_assoc is called. This is why your code is always displaying one result less than what was returned from the query, One fix would be to reset the internal row counter before the while loop using mysql_data_seek(0); Or echo the product name and description within the while loop when $i is zero. So remove lines 29 to 33 and add if($i === 0) { echo '<h1>'.$row['cat_name'].'</h1>'.$row['cat_description']; } After the while loop construct - while ($row = dbFetchAssoc($result)) { Edited January 22, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/285579-not-all-records-are-being-displayed/#findComment-1466154 Share on other sites More sharing options...
Solution bravo14 Posted January 22, 2014 Author Solution Share Posted January 22, 2014 Thanks a lot, fixed it Quote Link to comment https://forums.phpfreaks.com/topic/285579-not-all-records-are-being-displayed/#findComment-1466157 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.