实用程序PHP函数来分页SQL查询

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实用程序PHP函数来分页SQL查询相关的知识,希望对你有一定的参考价值。

  1. /**
  2. * A utility method that builds out the SQL for the LIMIT / OFFSET chunk of the SQL
  3. *
  4. * @param page the page that will be pulled, will affect the OFFSET
  5. * @param perpage how many items per page, will affect the LIMIT
  6. * @return string an SQL statement consisting of the LIMIT and OFFSET
  7. */
  8. private function _buildLimitOffsetSQL($page,$perpage) {
  9. $limit = (is_numeric($perpage) && $perpage>0) ? $perpage : 10;
  10. $offset = (is_numeric($page) && $page>0) ? ($page-1)*$perpage : 0;
  11. return "LIMIT $limit OFFSET $offset";
  12. }

以上是关于实用程序PHP函数来分页SQL查询的主要内容,如果未能解决你的问题,请参考以下文章