Home > Backend Development > PHP Tutorial > 又一个php 分页类实现代码_php技巧

又一个php 分页类实现代码_php技巧

WBOY
Release: 2016-05-17 09:29:19
Original
999 people have browsed it

复制代码 代码如下:

function genpage(&$sql,$page_size=10)
{
global $pages,$sums,$eachpage,$page; //总页数,总记录,每页数,当前页
$page = $_GET["page"];
if($page ==0)$page =1;
$eachpage = $page_size;
$pagesql = strstr($sql," from ");
$pagesql = "select count(*) as ids ".$pagesql;
$conn = mysql_query($pagesql) or die(mysql_error());
if($rs = mysql_fetch_array($conn))$sums = $rs[0];
$pages=ceil($sums/$eachpage);
if($pages==0)$pages=1;
$startpos = ($page-1)*$eachpage;
$sql .=" limit $startpos,$eachpage ";
}

//显示分页
function showpage()
{
global $pages,$sums,$eachpage,$page; //总页数,总记录,每页数,当前页,其它参数
$link=$_SERVER['PHP_SELF'];
echo "记录".$sums.":".$eachpage." ";
echo "页数".$page."/".$pages." ";
$p_head=$page-5;
if($p_head$p_end=$page+5;
if($p_end>$pages)$p_end=$pages; //页码循环结束数 后5个
echo "[首页] ";
for($i=$p_head;$i{
if($i!=$page)
echo "[$i] ";
else
echo "[$i] ";
}
echo " [末页]";
}
?>
Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template