开发者

SQL SELECT skip first N results?

开发者 https://www.devze.com 2023-03-25 01:13 出处:网络
This is my query: $result = mysql_query(\"SELECT * FROM Posts WHERE MATCH (City) AGAINST (\'$city\') ORDER by Date DESC LIMIT 10\");

This is my query:

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

Basically I want t开发者_运维技巧o 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?


Check the keyword OFFSET :

... LIMIT 10 OFFSET 10


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'");


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

0

精彩评论

暂无评论...
验证码 换一张
取 消