一个典型的PHP分页实例代码
Release: 2016-06-13 11:35:21
Original
869 people have browsed it
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
php make page list
ID |
文章标题 |
/*
* Created on 2010-4-17
*
* Order by Kove Wong
*/
$link=MySQL_connect(’localhost’,’root’,’haoxiazai1987’);
mysql_select_db(’pagelist’);
mysql_query(’set names gbk’);
$Page_size=10;
$result=mysql_query(’select * from v_char’);
$count = mysql_num_rows($result);
$page_count = ceil($count/$Page_size);
$init=1;
$page_len=7;
$max_p=$page_count;
$pages=$page_count;
//判断当前页码
if(empty($_GET[’page’])||$_GET[’page’]
$page=1;
}else {
$page=$_GET[’page’];
}
$offset=$Page_size*($page-1);
$sql="select * from v_char limit $offset,$Page_size";
$result=mysql_query($sql,$link);
while ($row=mysql_fetch_array($result)) {
?>
|
|
}
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量
$key=’’;
$key.=" $page/$pages "; //第几页,共几页
if($page!=1){
$key.=" 第一页 "; //第一页
$key.=" 上一页"; //上一页
}else {
$key.="第一页 ";//第一页
$key.="上一页"; //上一页
}
if($pages>$page_len){
//如果当前页小于等于左偏移
if($page
$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
if($i==$page){
$key.=’ ’.$i.’’;
} else {
$key.=" ".$i."";
}
}
if($page!=$pages){
$key.=" 下一页 ";//下一页
$key.=" 最后一页"; //最后一页
}else {
$key.="下一页 ";//下一页
$key.="最后一页"; //最后一页
}
$key.=’ ’;
?>
|
|
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31