tp3.2中利用分页类进行分页(多条件搜索)

时间:2021-07-26 08:24:12

HTML页面

用户名:<input type="text" name="name" id="username">
方案id:<input type="text" name="" id="programid">
配资状态:<select name="status" id="status">
    <option value="0">全部状态</option>
 <foreach name="cap_status" item="status">
     <option value="{$status.c_s_id}">{$status.c_s_name}</option>
 </foreach>
</select>
<input type="button" value="搜索" onclick="searcha()">

js传值

function searcha(){
        var status=document.getElementById("status").value;
        var username=document.getElementById("username").value;
        var programid=document.getElementById("programid").value;
        $.ajax({
            url:"__APP__/Fund/Fund/fund_list",
            type:"get",
            data:{"status":status,"username":username,"programid":programid},
            success:function(e){
                $("#lista").html(e);             
            }
        })
    }

传值到控制器并利用tp中的分页类进行多条件搜索并分页

public function fund_list(){
        $status=$_GET['status'];
        $username = $_GET['username'];
        $programid = $_GET['programid'];
    	//配资状态
		$cap_status = D("Fund")->fund_list();

        //实现分页及搜索
        $User = M('wcp_capital_apply'); // 实例化User对象
            $where="1=1";
            if($status){
                $where.=" and wcp_capital_status.c_s_id = '$status' ";
            }
            if($username){
                $where.=" and wcp_user.user_name='$username' ";
            }  
            if($programid){
                $where.=" and wcp_capital_apply.case_id='$programid'";
            }
        $count = $User->join("wcp_capital_status ON wcp_capital_apply.capital_status = wcp_capital_status.c_s_id")
        ->join("wcp_finace_type ON wcp_capital_apply.capital_type=wcp_finace_type.f_t_id")
        ->join("wcp_user ON wcp_capital_apply.user_id = wcp_user.user_id")
        ->field("cap_id,wcp_capital_apply.user_id,case_id,user_name,bond_price,apply_price,hailun_price,c_s_id,cordon_price,open_price,f_t_name,c_s_name,capital_use_time ")
        ->where($where)->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,2);// 实例化分页类 
        $show       = $Page ->show();// 分页显示输出
        $list = $User->join("wcp_capital_status ON wcp_capital_apply.capital_status = wcp_capital_status.c_s_id")
        ->join("wcp_finace_type ON wcp_capital_apply.capital_type=wcp_finace_type.f_t_id")
        ->join("wcp_user ON wcp_capital_apply.user_id = wcp_user.user_id")->order("cap_id asc")
        ->field("cap_id,wcp_capital_apply.user_id,case_id,user_name,bond_price,apply_price,hailun_price,c_s_id,cordon_price,open_price,f_t_name,c_s_name,capital_use_time ")
        ->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();
        //echo $User->getlastsql();
        $this->assign('cap_apply',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->assign("cap_status", $cap_status);
        $this->display();
    }