PHP 列表页 展示方法 修正版

WBOY
Release: 2016-06-13 12:00:36
Original
1270 people have browsed it

PHP 列表页 显示方法 修正版
数据库名称:persons
数据库表名:cs
数据库表字段:id   FirstName
数据库IP:localhost(本地)
数据库用户名:root
数据库密码:(空)
__________________________________________________________________




Untitled Document



     
   
 
     
        id 
        值 
       
            $link = mysql_connect("localhost","root",""); //连接数据库 
        mysql_select_db("cs");//选择哪个数据库 
        mysql_query("set names utf-8"); //设置数据库字符编码为中文 
        $sql = mysql_query("select *from persons"); 
        $pagesize = 5; //显示条数
        $sum = mysql_num_rows($sql); //判断 一共有多少条数据 
        $count = ceil($sum/$pagesize);//求出一共有多少页 
        $pages = $count; //显示最后一页 
        $init = 1; 
        $page_len = 7; 
        $max_p = $count;     
        if(empty($_GET["page"])|| $_GET["page"]            $page = 1; 
        }else{ 
            $page = $_GET["page"]; 
        } 
        $off = ($page-1)*$pagesize; //求出数据库查询的第一个数据 
        $he = mysql_query("select * from persons limit $off,$pagesize");//按照off开始,到pagesize规律显示
echo "一共 ".$sum." 条数据"; 

        while($row = mysql_fetch_array($he)){ 
        
    echo "";
    echo "".$row['id'].""; 
    echo "".$row['FirstName']."";
    echo " ";
        }
    ?>
      $page_len = ($page_len%2)?$page_len:$page_len+1;//如果余为1则为真,为0则为假 
    $pageoffset = ($page_len-1)/2;//页码偏移量
    $key ="";
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($i-1!=$page){ 
        $key.="下一页"; 
        $key.="最后一页"; 
    }else{ 
        $key.="下一页"; 
        $key.="最后一页"; 
    }

echo ""; 
echo "".$key."";  
echo "";
?>

     
     


__________________________________________________________________
如有问题请留言
Related labels:
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