-1

I want some help regarding PHP and MYSQL. What I'm trying is to create pagination system but with ORDER in a field value. Like I'm fetching 700 rows initially, afterward I want next 700 rows with the same order excluding the previous rows.

Here is my query:

$sql = "SELECT * FROM table WHERE user LIKE '%$user%' ORDER BY points DESC LIMIT 700";

Now, I want the next 700 rows excluding the ones I got in the first request. Same goes if user requests page 3rd and get 700 records excluding first 1400(700*2) records.

Thanks :)

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107

1 Answers1

-1

Limit can be used with 2 values, the beginning and end of the LIMIT Your 1st page for example:

$sql = "SELECT * FROM table WHERE user LIKE '%$user%' ORDER BY points DESC LIMIT 0,700";

basically, if page is the variable $p, starting at 1 then:

$sql = "SELECT * FROM table WHERE user LIKE '%$user%' ORDER BY points DESC LIMIT " . (($p - 1) * 700) . ", " . ($p * 700);

Of course, you're 700 jump can also be dynamic, $jump:

$jump = 700; // or any other value...

$sql = "SELECT * FROM table WHERE user LIKE '%$user%' ORDER BY points DESC LIMIT " . (($p - 1) * $jump) . ", " . ($p * $jump);
Guy Louzon
  • 1,175
  • 9
  • 19