PHP 用于对SQL查询进行分页的实用PHP函数

Posted

tags:

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

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

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