sql 复习:
SELECT * FROM table LIMIT count;
SELECT * FROM table LIMIT offset, count;
测试代码
namespace app\api\controller;
use app\common\model\NewsModel;
class NewsApi
{
public function page(){
$page = input("page", 1);
$size = input("size", 20);
echo NewsModel::limit($size)->page($page)->buildSql();
}
}
分页测试
/api/page?size=10&page=1
( SELECT * FROM `news` LIMIT 0,10 )
api/newsapi/page?size=10&page=2
( SELECT * FROM `news` LIMIT 10,10 )
api/newsapi/page?size=10&page=3
( SELECT * FROM `news` LIMIT 20,10 )
/api/newsapi/page?size=10&page=10
( SELECT * FROM `news` LIMIT 90,10 )