zoukankan      html  css  js  c++  java
  • [转]ThinkPHP中分页加上搜索

    ThinkPHP 分页可以很容易的实现对不固定查询参数的支持。具体实现是给分页类的 parameter 属性赋值或者直接实例化分页类时传入查询参数。下面以例子来说明。
    parameter 属性赋值

    例如要检索用户表中状态为 1 (status=1) 并且电子包含 163 的用户,当提交表单时(注意表单是 GET 方式提交),形成的 URL 地址大致如下:

    public function search(){

        $Dao = M("User");

        // 构造查询条件

        $condition['status'] = $_GET['status'];

        $condition['email'] = array('like',"%".$_GET['email']."%");

        // 计算总数

        $count = $Dao->where($condition)->count();

        // 导入分页类

        import("ORG.Util.Page");

        // 实例化分页类

       $p = new Page($count, 10);

        // 获取查询参数

        $map['status'] = $_GET['status'];

        $map['email'] = $_GET['email'];

        foreach($map as $key=>$val) { 

            $p->parameter .= "$key=".urlencode($val)."&"; 

        }

        // 分页显示输出

        $page = $p->show();

     

        // 当前页数据查询

        $list = $Dao->where($condition)->order('uid ASC')->limit($p->firstRow.','.$p->listRows)->select();

     

        // 赋值赋值

        $this->assign('page', $page);

        $this->assign('list', $list);


        $this->display();

    }

  • 相关阅读:
    Jooq基本操作
    SpringcloudStream简单使用
    SpringcloudBus消息总线
    RabbitMQ集群
    Springboot整合RabbitMQ
    RabbitMQ死信队列与延迟队列
    RabbitMQ事务性消息和确认模式
    公链简介
    公链简介
    Windows生产力工具推荐
  • 原文地址:https://www.cnblogs.com/xiaofeng028/p/3912174.html
Copyright © 2011-2022 走看看