Home  >  Article  >  Backend Development  >  如何给计算距离的sql加上分页

如何给计算距离的sql加上分页

WBOY
WBOYOriginal
2016-06-13 12:20:271278browse

怎么给计算距离的sql加上分页
$query=mysql_query('select * from shop where lat > '.$lat.'-1 and lat  '.$lng.'-1 and lng 
这语句。如果是正常下limit  后面是分页的页数和一页几条。但我加上距离计算后。limit 100的作用只起到了计算100公里内容的数据。分页的页数和一页几条的语句就不能加上。如果加上就不能显示。这是为什么?如何更改?

------解决思路----------------------
limit 100 是最多返回100条记录,与逻辑没有关系的。

limit $offset, $limit;
$offset是跳过多少条记录开始
$limit 是取多少条记录
用这两个就可以获取到分页

例如
$page = 2;
$pagesize 100;

limit (2-1)*100, 100; 就可以获取第二页的记录。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn