zoukankan      html  css  js  c++  java
  • php数据分页显示

    <!--
    分页插件的使用
    $p=new Page();
    $p->init_pagedate($counts, $pagesize, $page, $url);//$counts 查询记录数 / $pagesize每页显示记录数 / $page当前页码 / url 页码指向的地址
    $p->pageshow();
    -->

    <style type="text/css">
    #pages{
    font:9pt Verdana,Tahoma;
    color:#625F5F;
    }

    #pages a {
    margin:3px;
    padding:3px;
    color:#175CBB;
    border:1px dashed #D5E4F4;
    background:#F4FAFF;
    text-decoration: none;
    }

    #pages a:hover {
    border:1px solid #7AB7F3;
    color:#fff;
    background:#7AB7F3;
    text-decoration:none;
    }

    #pages span {
    margin:3px;
    padding:3px;
    color:#fff;
    background:#7AB7F3;
    }

    </style>
    <?php
    /**
    * 分页类
    */
    class Page
    {
    var $records; //需要分页显示的数据记录数
    var $pagesize;//页面显示记录数,默认10条
    var $page;//当前页码,默认是第1页
    var $pages=1;//总页数
    var $offset=0;//位移,数据库默认从第0条记录开始:select * from tablename limit 0, 10
    var $url;//页面地址

    /**
    * $pagesize\$records记录总数\$url\$page当前页码
    */
    function init_pagedata($records=0, $pagesize=10, $page=1, $url)//创建页面数据
    {
    $this->records = $records;
    $this->pagesize = $pagesize;
    $this->page = $page;
    $this->url = $url;
    $this->pages = $records%$pagesize==0 ? intval($records/$pagesize) : (intval($records/$pagesize))+1;
    $this->offset = ($page-1) * $pagesize;
    }

    function pageshow()//分类功能
    {
    echo "<div id=\"pages\">";
    echo "留言总数:". $this->records . "条&nbsp;&nbsp;&nbsp; 第[".$this->page."/".$this->pages."]页 ";
    if ($this->page > 4) {//首页
    $this->firstSign();
    }
    if($this->page != 1){//上一页
    $this->preSign();
    }

    if ($this->pages<=10) {
    for ($i=1; $i <=$this->pages ; $i++) {
    $this->numshow($i);
    }
    }
    else
    {
    if ($this->page <= 3) {
    for ($i=1; $i <=10 ; $i++) {
    $this->numshow($i);
    }
    }
    else
    {
    if ($this->page+6 > $this->pages) {
    $firststation = $this->pages - 10;
    for ($i=$firststation; $i <= $this->pages; $i++) {
    $this->numshow($i);
    }
    }
    else
    {
    $firststation = $this->page - 3;
    $laststation = $this->page + 6;

    for ($i=$firststation; $i <= $laststation; $i++) {
    $this->numshow($i);
    }
    }
    }
    }
    if($this->page != $this->pages && $this->pages != 0){//下一页
    $this->nextSign();
    }
    if ($this->page < $this->pages-6) {
    $this->lastSign();
    }
    echo "</div>";
    }

    function echoAlink($page)//输出a标签
    {
    echo "<a href='". $this->url."?page=".$page."'>".$page."</a>";
    }
    function echoSpan($page)//输出span标签
    {
    echo "<span>".$page."</span>";
    }
    function numshow($i)
    {
    if ($this->page==$i) {
    $this->echoSpan($i);
    }
    else
    {
    $this->echoAlink($i);
    }
    }
    function firstSign()//首页
    {
    echo "<a href='". $this->url."?page=1' style='font-family:webdings;'>7</a>";
    }
    function preSign()//上一页
    {
    echo "<a href='". $this->url."?page=".($this->page-1)."' style='font-family:webdings;'>3</a>";
    }
    function nextSign()//下一页
    {
    echo "<a href='". $this->url."?page=".($this->page+1)."' style='font-family:webdings;'>4</a>";
    }
    function lastSign()//尾页
    {
    echo "<a href='". $this->url."?page=".$this->pages."' style='font-family:webdings;'>8</a>";
    }
    }

    ?>

  • 相关阅读:
    java——ArrayList中remove()方法疑问总结
    java——ArrayList中contains()方法中的疑问
    C语言中signed和unsigned理解
    IO流——常用IO流详解
    Lost's revenge
    Searching the String
    DNA repair
    Ring
    Wireless Password
    Censored!
  • 原文地址:https://www.cnblogs.com/something/p/2728764.html
Copyright © 2011-2022 走看看