Home >Backend Development >PHP Tutorial >Discussion on PHP paging principle, an example of PHP paging code

Discussion on PHP paging principle, an example of PHP paging code

WBOY
WBOYOriginal
2016-07-25 08:52:531004browse
  1. select * from book limit 0,5;
  2. select * from book limit 5,5;
  3. select * from book limit 10,5;
Copy code

The first sentence is to find 5 from zero The second piece of information is to search for 5 pieces of information starting from 5. Needless to say the third piece of information.

First of all, 0=(1-1)*5, 5=(2-1)*5, 10=(3-1)*5. Here you need to understand what 1, 2, 3 represent, and what 5 represents. Whatever it is is fine. 1, 2, and 3 represent the current page, that is, the first, second, and third pages; 5 is the number of records displayed.

Get the query formula:

  1. select * from book limit($pageval-1)*$pagesize,$pagesize;
Copy the code

How to get the $page value. Use $_GET(page) to obtain it here.

Specific steps: First, determine the number of output records $pagesize=5; Use $url=$_srever["request_uri"]; To get the current url; then parse the url through parse_url(), and finally get the path value. This is the url required in paging.

php paging code:

[code] include "conn.php"; include "head.php"; ?> $pagesize=5; $url=$_SREVER["REQUEST_URI"];//获取当前的URL $url=parse_url($url);//将URL解析成数组 $url=$url[path];//取得path; $numq=mysql_query("select * from `book`"); $num = mysql_num_rows($numq);//遍历数组 if($_GET


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