zoukankan      html  css  js  c++  java
  • thinkphp分页效果的制作,按查询条件分页正确做法

    PHP代码:

    <?php
    namespace HomeController;
    use ThinkController;
    use HomeClasCate;
    class IndexController extends Controller {
        public function index(){
            $where=I('get.');//得到传递的参数数组,没有为空,搜索全部,有的话按条件搜索
            $count=M('user')->where($where)->count();
            $pagecount=10;
            $page=new ThinkPage($count,$pagecount);
            $page->setConfig('first','首页');
            $page->setConfig('prev','上一页');
            $page->setConfig('next','下一页');
            $page->lastSuffix=false;//不加此代码,尾页不显示
            $page->setConfig('last','尾页');
            $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
            $res=M('user')->where($where)->limit($page->firstRow.','.$page->listRows)->select();
            $show=$page->show();
            $this->assign('res',$res);
            $this->assign('page',$show);
            $this->display();
        }
    }

    HTML代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <style> 
        .pagelist{ 
          text-align:center; 
          background:#f1f1f1; 
          padding:7px 0;
        }
        .pagelist a{
          text-decoration: none; 
          margin:0 5px; 
          border:#6185a2 solid 1px;
          display:inline-block;
          padding:2px 6px 1px; 
          line-height:16px; 
          background:#fff; 
          color:#6185a2;
        }
        /*点击页码之后改变此点击页码的字体颜色和背景色,span为分页类内部的标签*/
        .pagelist span{
          margin:0 5px;
          border:#6185a2 solid 1px;
          display:inline-block;
          padding:2px 6px 1px; 
          line-height:16px;
          color:#fff; 
          background:#6185a2;
        }
      </style>
    </head>
    <body>
      <table align='center'> 
        <tr>
          <td>id</td><td>姓名</td><td>密码</td><td>性别</td><td>年纪</td><td>邮件</td><td>主页</td><td>薪水</td>
        </tr>
        <volist name='res' id='v'>
        <tr><td>{$v.id}</td><td>{$v.name}</td><td>{$v.password}</td><td>{$v.sex}</td><td>{$v.age}</td><td>{$v.email}</td><td>{$v.mypage}</td><td>{$v.salary}</td></tr>
        </volist>
      </table>
      <div class='pagelist'>
        {$page}
      </div>
      <div align='center'>
        <br><br>
        <a style='text-decoration:none' href="{:U('index',array('name'=>'ok'))}"><span style='border:1px solid green;background-color:green;color:white;border-radius:10px;padding:10px'>名字为ok的列表</span></a><br><br><br>
        <a style='text-decoration:none' href="{:U('index')}"><span style='border:1px solid green;background-color:green;color:white;border-radius:10px;padding:10px'>全部</span></a>
      </div>
    </body>
    </html>

    效果图:

     

  • 相关阅读:
    kubadm初始化找不到镜像
    ssh登录等待时间长问题
    6.vue之v-html
    5.vue之v-text
    4.vue之data对象
    3.vue之el:挂载点
    2.vue基础test
    1.vue之软件VSCode(自动刷新)
    java计算金额保留两位小数精确到分(四舍六入五成双)
    win7 64位 旗舰版装系统记录及window简记
  • 原文地址:https://www.cnblogs.com/hltswd/p/5137784.html
Copyright © 2011-2022 走看看