Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Using LIMIT Missing Last Entries

Using LIMIT Missing Last Entries

Using LIMIT Missing Last Entries

Using a simple page navigator that gives basic Page navigation to build the LIMIT clause dynamically seems to give unexpected results. For example, limiting results to 20 records but having a record set containing 23 records, when I select Page 2, it is empty but when I select Page 1 again, there the last three are.

The HTML navigator is something like this with the current page in-linked in square brackets:


<div class="Pagination">[1]
<a href="/categories/help/sitesearch.php?Page=2" title="To page 2">2</a></div> 

. . . and the PHP building the conditional to append to the end of the query is:


if ($_GET['Page']) :
	$Offset = (20 * $_GET['Page']) + 1;
	$Query .= " LIMIT $Offset, 20";
	$Query .= " LIMIT 0, 20";

I see what it's doing - for Page 2 it is giving LIMIT 41, 20 and worked it out so that it works and gives the proper LIMIT 21, 20 but it seems cumbersome so I'm wondering if there is a better way:


if ($_GET['Page']) :
	$Offset = (20 * $_GET['Page']) - 19;
	$Query .= " LIMIT $Offset, 20";
	$Query .= " LIMIT 0, 20";

RE: Using LIMIT Missing Last Entries

for twenty results per page your $offset should be

CODE --> php

20 * ($page -1) 

Otherwise page 2 will start at row 40, 3 at row 60 and so on


Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Using LIMIT Missing Last Entries

Thank you! It seems to work as well as my $Offset = (20 * $_GET['Page']) - 19; did but yours makes more sense and looks cleaner.

RE: Using LIMIT Missing Last Entries

in case you ever find it useful there is a data paging FAQ with sample code written by sleipnir214 in the php forum

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close