lisovaccaro
lisovaccaro

Reputation: 33956

SQL SELECT skip first N results?

This is my query:

    $result = mysql_query("SELECT * FROM Posts WHERE MATCH (City) AGAINST ('$city') ORDER by Date DESC LIMIT 10");

Basically I want to skip the first 10 results and only select result N: $page * 10 to show the results that correspond to that page. How can I do this?

Upvotes: 2

Views: 7068

Answers (3)

Jeune
Jeune

Reputation: 3538

Use

Limit 10,10

Where the first 10 is the offset and the second 10 is how many rows you want to retrieve after the offset

Upvotes: 1

sclarson
sclarson

Reputation: 4422

You're looking for the OFFSET keyword

$offset = $page*10;
$result = mysql_query("SELECT * FROM Posts WHERE MATCH (City) AGAINST ('$city') ORDER by Date DESC LIMIT 10 OFFSET '$offset'");

Upvotes: 3

Vincent Savard
Vincent Savard

Reputation: 35927

Check the keyword OFFSET :

... LIMIT 10 OFFSET 10

Upvotes: 4

Related Questions