php实现的仿阿里巴巴实现同类产品翻页,分页带

2019-07-28 10:34 来源:未知

若是左侧的笔录条数小于$space(页码区段)的值,页码$start从1起来向右增值。要是左则的笔录条数多于$left(左右各展现页数)的值,$start将从左侧记录数减去$left值开端记数。

thinkphp 默认的分页体制很倒霉看,分页多了就能油但是生样式错乱,如何兑现分页带有省略号啊?其实方法很轻便。那么些方法自然,无公害。
代码如下:

类文件 : _class.xmldb.inc.php

复制代码 代码如下:

 代码如下

复制代码 代码如下:

<?php
/** 达成同类产品翻页 **/

class IndexAction extends Action {
    public function index() {       
        $M = M("Article_21");
        $count = $M->count();
        import("ORG.Util.Page");
        $page = new Page($count, 10);
        //$showPage = $page->show();//Thinkphp原有的秘技
        $showPage = $page->shows();//自定义的不二等秘书技
        $list=$M->limit($page->firstRow, $page->listRows)->select();;
       
        $this->assign("page", $showPage);
        $this->assign("list",$list);
        $this->display();
    }
}

<?php
class xmldb extends DOMDocument{
    var $xmldb;
    public function __construct($xmldbname){
        $this->xmldb=$xmldbname;
        if(!file_exists($this->xmldb)){
            $initxmldb = "<?xml version="1.0" encoding="utf-8"?><Message></Message>";
            $this->loadXML($initxmldb);
            $this->save($this->xmldb);
        }else{
            $this->load($this->xmldb);
        }

class pager
{
protected $space;
protected $left;
protected $DB;
protected $pageName;

找到Thinkphp宗旨包中的分页类
在底下增添一下代码:

    }
    public function insert_message($nickname,$message){

public function setSpace($num) {
$this->space = $num;
$this->left = ceil(($num-1)/2);
}

 代码如下

        $messagedom = $this->getElementsByTagName("Message");
        $subnode = $this->createElement("Rows");
        $nicknamenode = $this->createElement("Nickname");
        $nicknamenode -> appendChild($this->createTextNode($nickname));
        $subnode -> appendChild($nicknamenode);
        $contentnode = $this->createElement("Content");
        $contentnode -> appendChild($this->createTextNode($message));
        $subnode -> appendChild($contentnode);
        $timernode = $this->createElement("Timer");
        $timernode -> appendChild($this->createTextNode(time()));
        $subnode -> appendChild($timernode);
        $messagedom->item(0)->appendChild($subnode);
        $this->saveXML();
        $this->save($this->xmldb);
    }
    function get_node_www.weide1946.com,length($nodename){

public function setDB(&$db) {
$this->DB = $db;
}

public function shows()
    {
    $adjacents=2;
    if(0 == $this->totalRows) return '';
    $p              =   $this->varPage;
    $nowCoolPage    =   ceil($this->nowPage/$this->rollPage);
       
    // 剖判分页参数
    if($this->url){
        $depr       =   C('URL_PATHINFO_DEPR');
        $url        =   rtrim(U('/'.$this->url,'',false),$depr).$depr.'__PAGE__';
    }else{
        if($this->parameter && is_string($this->parameter)) {
            parse_str($this->parameter,$parameter);
        }elseif(is_array($this->parameter)){
            $parameter      =   $this->parameter;
        }elseif(empty($this->parameter)){
            unset($_GET[C('VAR_URL_PARAMS')]);
            $var =  !empty($_POST)?$_POST:$_GET;
            if(empty($var)) {
                $parameter  =   array();
            }else{
                $parameter  =   $var;
            }
        }
        $parameter[$p]  =   '__PAGE__';
        $url            =   U('',$parameter);
    }   
   
    //上下翻页字符串
    $upRow          =   $this->nowPage-1;
    $downRow        =   $this->nowPage 1;
   
    // 上一页
    if ($upRow>0){
         $pages.=   "<a href='".str_replace('__PAGE__',$upRow,$url)."' class='prev'>".$this->config['prev']."</a>";
    }else{
         $pages.=   "<a class='prev current'>".$this->config['prev']."</a>";
    }
    
    //第一页
    if($this->nowPage>($adjacents 1)) {
        $pages.= "<a href='".str_replace('__PAGE__',1,$url)."'>1</a>";
    }
    
    // 加多省略号
    if($this->nowPage>($adjacents 2)) {
        $pages.= "<a>...</a>";
    }
    
    // 12345
    $pmin = ($this->nowPage>$adjacents) ? ($this->nowPage-$adjacents) : 1;
    $pmax = ($this->nowPage<($this->totalPages-$adjacents)) ? ($this->nowPage $adjacents) : $this->totalPages;
    for($i=$pmin; $i<=$pmax; $i ) {
        if($i==$this->nowPage) {
            $pages.= "<a class='current'>".$i."</a>";
        }else{
            $pages.= "<a href='".str_replace('__PAGE__',$i,$url)."'>".$i."</a>";
        }
    }
    
    // 增添省略号
    if($this->nowPage < ($this->totalPages-$adjacents-1)) {
        $pages.= "<a>...</a>";
    }
    
    // 最后一页
    if($this->nowPage<($this->totalPages-$adjacents)) {
       
        $pages.= "<a href='".str_replace('__PAGE__',$this->totalPages,$url)."'>".$this->totalPages."</a>";
    }
    
    // 下一页
    if ($downRow <= $this->totalPages){
         $pages.=   "<a href='".str_replace('__PAGE__',$downRow,$url)."' class='next'>".$this->config['next']."</a>";
    }else{
        $pages.=   "<a  class='next current'>".$this->config['next']."</a>";
    }
    return $pages;
    }
html代码:
<html>
    <head>
        <title></title>
    </head>
    <style>
    a{text-decoration:none;}
    .pages a{
    border: 1px solid #ccc;
    display: inline-block;
    height: 20px;
    line-height: 20px;
    margin: 0 5px;
    text-align: center;
    width: 20px;
    color:#222;
    background-color:#eee;
    }
    .pages >.prev {width:60px;}
    .pages >.next {width:60px;}
    .pages >.current{color:red;border: 1px solid red;}
    .box ul li{list-style:none;}
    </style>
    <body>
        <div>
            <div class="box">
                <ul>
                <volist name="list" id="v" key="k">
                    <li>{$k}->{$v.title}</li>
                </volist>   
                </ul>
            </div>
            <div class="pages">
                {$page}
            </div>
        </div>
    </body>
</html>

        $odom = $this->getElementsByTagName($nodename);
        return $odom->length;
    }
    public function get_message_list($start,$rowscount,$pagesize){
        $end = $rowscount > $pagesize ? $start $pagesize : $rowscount;

public function setPageName($pageName) {
$this->pageName = $pageName;
}

效果图:

        $k = 0;
        for($i = $start; $i < $end; $i ){
            $rowslist[$k]["Nickname"] = $this->getElementsByTagName("Nickname")->item($i)->nodeValue;
            $rowslist[$k]["Content"] = $this->getElementsByTagName("Content")->item($i)->nodeValue;
            $rowslist[$k]["Timer"] = $this->getElementsByTagName("Timer")->item($i)->nodeValue;
            $k ;
        }
        return $rowslist;
    }
    public static function splitpage($pageall,$page=1,$urled=null,$strpage = "page",$pageaverage = 10){
            $pageaverage -= 1;
            $page = intval($page >=1 ? $page : 1 );
            $page = $page > $pageall ? $pageall : $page;
            $startpage = $page - $pageaverage > 0 ? $page - ceil(($pageaverage / 2)):1;
            $startpage = ($page ceil($pageaverage/2) > $pageall)?$pageall-$pageaverage:$startpage;

public function getPages($catid, $exptime) {
$fields = array("`id`,`title`");
$left = array(">" => array("exptime"=>$exptime), "memberid" => gs(_MEM_PREFIX_ . "memberid"), "catid"=>$catid);
$right = array("<" => array("exptime"=>$exptime), "memberid" => gs(_MEM_PREFIX_ . "memberid"), "catid"=>$catid);

www.weide1946.com 1

            $startpage = $startpage > 0 ? $startpage : 1;
            $stoppage = $startpage $pageaverage >$pageall?$pageall:$startpage $pageaverage;
            if(empty($urlfile)){ $urlfile=$_SERVER["PHP_SELF"]; }
            if(!strrpos($urlfile,'?')) $urled .= '?';
            foreach($_GET as $k => $v)
            {
                $urled = ($k<>$strpage) ? $urled.$k.'='.urlencode($v).'&' : $urled;
            }
            if ($page>1){
                $mess ="<a href="".$urled.$strpage."=1" href="".$urled.$strpage."=1">首页</a> ";
                $mess .="<a href="".$urled.$strpage."=".($page-1)."" href="".$urled.$strpage."=".($page-1)."">上一页 </a>";
            }else{
                $mess ="首页 ";
                $mess .="上一页 ";
            }
            if($page > 9){
                $startpage = $page - 9;
            }
            $stoppage = $startpage 9 >= $pageall ? $pageall : $startpage 9;
            for($i= $startpage; $i<= $stoppage ;$i )
            {
                if($i<= $pageall && !($page==$i))
                    $mess .= "<a href="".$urled.$strpage."=".$i."" href="".$urled.$strpage."=".$i."">".$i."</a> ";
                else
                    $mess .= "".$i." ";
            }
            if ($page < $pageall){
                $mess .=" <a href="".$urled.$strpage."=".($page 1)."" href="".$urled.$strpage."=".($page 1)."">下一页</a>";
                $mess .=" <a href="".$urled.$strpage."=".$pageall."" href="".$urled.$strpage."=".$pageall."">尾页</a>";
            }else{
                $mess .=" 下一页";
                $mess .=" 尾页";
            }
        return $mess;
    }
}
?>

$leftCount = $this->DB->getCount($left);

调用文件 : index.php

if($leftCount <= $this->left) {
$star = 1;
$leftLimit = "LIMIT" . $leftCount;
$rightLimit = "LIMIT " . ($this->space-$leftCount);
}
else {
$start = $leftCount - $this->left;
$leftLimit = "LIMIT " . $this->left;
$rightLimit = $leftLimit;
}

复制代码 代码如下:

$list1 = $this->DB->findAll($left, array("exptime"=>"ASC"), $leftLimit, $fields);
$list2 = $this->DB->findAll($right, array("exptime"=>"DESC"), $rightLimit, $fields);

<?php
require("_class.xmldb.inc.php");
$xmldb = new xmldb("./my_xmldb.xml");
if(isset($_POST["btnform1"])){
    $xmldb -> insert_message($_POST["nickname"],$_POST["content"]);
}
$pagesize        = 3;
$page            = !empty($_GET['page']) ? intval($_GET['page']) : 1;
$rowscount        = $xmldb -> get_node_length("Rows");
$pagecount        = ceil($rowscount/$pagesize);
$start            = ($page-1)*$pagesize > $rowscount ? $rowscount : ($page-1)*$pagesize;
$rowslist = $xmldb -> get_message_list($start,$rowscount,$pagesize);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE> New Document </TITLE>
    <style type='text/css'><!--
        #messagelist ul li{ float:left;list-style-type:none; }

/** 上一页链接 **/
$c = count($list1);
if($c > 1) {
$url = $this->pageName."-".$list1[$c]['id'].".html";
$pages = "<a href="{$url}">上一页</a><ol>";
}elseif($c == 1) {
$url = $this->pageName."-".$list1[0]['id'].".html";
$pages = "<a href="{$url}">上一页</a><ol>";
}else {
$pages = "";
}

--></style><style type='text/css' bogus="1">        #messagelist ul li{ float:left;list-style-type:none; }
    </style>
</HEAD>
<BODY>
    <div id="messagelist">
    <?php
        if(!empty($rowslist))
        {
            foreach($rowslist as $key => $value)
            {
                echo "<ul><li>".$value["Nickname"]." <span>(".date("Y-m-d H:i",$value["Timer"]).")</span></li>";
                echo "<li>".$value["Content"]."</li></ul><br>";
            }
        }
    ?>
        <div><?=$xmldb -> splitpage($pagecount,$page,'','page',$pagesize)?></div>
    </div>
    <div>
        <form action="" method="post" name="form1">
            昵称:<input type="text" name="nickname"><br>
            内容:<textarea name="content">

/** 当前页的侧边内容 **/
foreach($list1 as $item) {
$url = $this->pageName."-".$item['id'].".html";
$pages .= "<li><a href="{$url}">{$start}</a></li>";
$start ;
}

php操作xml的简便留言板,带分页,仅供参谋

$pages .= "<li><b>{$leftCount}</b></li>";
$start ;

你或者感兴趣的稿子:

  • 一个简练的PHP&MYSQL留言板源码
  • php轻松的留言板与还原功用具体贯彻
  • php开拓留言板的CRUD(增,删,改,查)操作
  • 源于精粹的制作轻便的PHP&MYSQL留言板
  • 一个可分页的基于文本的PHP留言板源码
  • 找到一款不错的根据AJAX留言板源码(PHP版、ASP版)提供下载了
  • php制作文本式留言板
  • php达成网址留言板功效
  • PHP结合Mysql数据库达成留言板效率
  • php达成留言板成效(会话调控)

/** 当前页面侧边的情节 **/
foreach($list1 as $item) {
$url = $this->pageName."-".$item['id'].".html";
$pages .= "<li><a href="{$url}">{$start}</a></li>";
$start ;
}

/** 下一页的链接 **/
$c = count($list2);
if($c > 0) {
$url = $this->pageName."-".$list2[0]['id'].".html";
$pages .= "<a href="{$url}">下一页</a><ol>";
}else {
$pages .= "";
}

return $pages;
}
};
?>

你恐怕感兴趣的小说:

  • php普通话本数据翻页(留言本翻页)
  • 什么样编写翻页函数?
  • 点图片上一页下一页翻页效果
  • PHP 翻页 实例代码
  • PHP 长小说分页函数 带使用方式,不会分开段落,翻页在底层
  • 在图纸上显得左右箭头类似翻页的代码
  • 分析Android中贯彻滑动翻页之ViewFlipper的施用详解
  • 通过MySQL优化Discuz!的热帖翻页的技巧
  • PHP翻页跳转功效完结形式
  • MongoDB快速翻页的办法
版权声明:本文由韦德娱乐1946_韦德娱乐1946网页版|韦德国际1946官网发布于网络编程,转载请注明出处:php实现的仿阿里巴巴实现同类产品翻页,分页带