angel1987 Posted August 6, 2013 Share Posted August 6, 2013 I noticed a bug in my script and i have been searching a lot on internet since past few hours but i could not find any information or solution. The script runs fine, no errors, but the script does not fetch last row/entry. Example, if there are 3 rows in the table, my script only pulls 2 rows. If there are 10, then only 9 are fetched. Please help me find the bug. Here is my script... <?php $query = "SELECT * FROM members WHERE $condition_res ORDER BY id DESC LIMIT $startpoint, $limit"; $result_query = mysqli_query($mysqli, $query); while($row = @mysqli_fetch_assoc($result_query)) { $mid=$row["id"]; $member=$row["name"]; $gender= $row["gender"]; ?> <tr> <td><?php echo $mid; ?></td> <td><?php echo $member; ?></td> <td><?php echo $gender; ?></td> </tr> <?php } ?> Note: $startpoint and $limit variables are for Pagination. $condition_res is for search criteria. Quote Link to comment https://forums.phpfreaks.com/topic/280878-php-mysqli-does-not-fetch-last-row-from-the-table/ Share on other sites More sharing options...
boompa Posted August 6, 2013 Share Posted August 6, 2013 (edited) Totally guessing because of the dearth of code, but I suspect it has to do with your pagination logic, which you do not show. Why are you suppressing errors on your mysqli_fetch_assoc? Why aren't you using prepared statements? Are you sanitizing your conditional input? Edited August 6, 2013 by boompa Quote Link to comment https://forums.phpfreaks.com/topic/280878-php-mysqli-does-not-fetch-last-row-from-the-table/#findComment-1443645 Share on other sites More sharing options...
cyberRobot Posted August 6, 2013 Share Posted August 6, 2013 Have you looked closely at the values for the LIMIT clause? LIMIT $startpoint, $limit I suspect it might be an offset issue. The following quote was pulled from http://dev.mysql.com/doc/refman/5.0/en/select.html: With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): Quote Link to comment https://forums.phpfreaks.com/topic/280878-php-mysqli-does-not-fetch-last-row-from-the-table/#findComment-1443665 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.