PHP paging function code

不言
Release: 2023-03-24 06:58:01
Original
1690 people have browsed it

This article introduces the PHP paging function code, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

Prepare data:

New A database test
Execute the following statement (create a new table test: three fields of id, sex, and name)

CREATE TABLE `test` ( `id` INT( 4 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `sex` INT( 1 ) NOT NULL , `name` VARCHAR( 20 ) NOT NULL ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_bin;
Copy after login

Add data to the test table, such as:
1 1 Xiaoqiang
2 0 Xiaohong
3 0 Xiaoli
4 1 Xiaobing
5 1 Zhang San
6 0 Li Si
7 0 Wu Xin
PHP paging function code
Write PHP statement (index.php):

Copy codeThe code is as follows:

= $page_count) $page = $page_count; $select_limit = $page_size; $select_from = ($page - 1) * $page_size.','; $pre_page = ($page == 1)? 1 : $page - 1; $next_page= ($page == $page_count)? $page_count : $page + 1 ; $pagenav .= "第 $page/$page_count 页 共 $rows 条记录 "; $pagenav .= "首页 "; $pagenav .= "前一页 "; $pagenav .= "后一页 "; $pagenav .= "末页"; $pagenav.=" 跳到