一个PHP分页代码,函数形式,返回起始页
PHP分页代码
调用: $start=show_page($query,$page,$link,$offset);
其中: $start为起始记录
$query为全记录检索SQL语句
$page为当前页码
$link为传递的页面参数
$offset为每页显示记录数
<?php //======function.php===== //======分页函数========== function show_page($query,$page,$link,$offset) { $db = new mysql(); $result = $db->query($query); $Page_size = $offset; //取得每页显示的最大订单数 $count = $db->affected_rows($result); //总订单数 $page_count = ceil($count/$Page_size); //计算得出总页数 $init=1; $page_len=7; $max_p=$page_count; $pages=$page_count; //判断当前页码 $page=(empty($page)||$page<0)?1:$page; $start=$Page_size*($page-1); //分页功能代码 $page_len = ($page_len%2)?$page_len:$pagelen+1; //页码个数 $pageoffset = ($page_len-1)/2; //页码个数左右偏移量 $key="共 $count 条 "; $key.="$page/$pages ";//第几页,共几页 if($page!=1){ $key.="<a href="".$_SERVER['PHP_SELF']."?page=1&$link">第一页</a>";//第一页 $key.="<a href="".$_SERVER['PHP_SELF']."?page=".($page-1)."&$link">上一页</a>";//上一页 } else { $key.="第一页";//第一页 $key.="上一页";//上一页 } if($pages>$page_len) { //如果当前页小于等于左偏移 if($page<=$pageoffset){ $init=1; $max_p = $page_len; } else //如果当前页大于左偏移 { //如果当前页码右偏移超出最大分页数 if($page+$pageoffset>=$pages+1){ $init = $pages-$page_len+1; } else { //左右偏移都存在时的计算 $init = $page-$pageoffset; $max_p = $page+$pageoffset; } } } for($i=$init;$i<=$max_p;$i++) { if($i==$page){$key.=' ['.$i.']';} else {$key.="<a href="".$_SERVER['PHP_SELF']."?page=".$i."&$link">".$i."</a>";} } if($page!=$pages) { $key.="<a href="".$_SERVER['PHP_SELF']."?page=".($page+1)."&$link">下一页</a>";//下一页 $key.="<a href="".$_SERVER['PHP_SELF']."?page=".$pages."&$link">最后一页</a>";//最后一页 } else { $key.="下一页"; //下一页 $key.="最后一页";//最后一页 } echo"$key<BR><BR>"; return $start; } ?>
<?php include("../include/mysql.class.php"); include("../include/function.php"); $query ="select * from $table order by id desc"; $offset=($_GET[offset]!='')?$_GET[offset]:$offset; $start=show_page($query,$_GET[page],"offset=$offset",$offset); $db->close(); ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
