• yii2.0分页搜索自己写的代码


     //控制器
    public function actionYulist(){
    $start = yii::$app->request->get('start');//接收要搜索的数据
    $end = yii::$app->request->get('end');//接收要搜索的数据
    $where = "1=1";//拼接条件
    if(!empty($start)&&!empty($end)){//拼接条件
    $where .= " and `begintime`>='$start' and `begintime`<='$end'";
    }
    if(!empty($start)){//拼接条件
    $where .= " and `begintime`>='$start'";
    }
    if(!empty($end)){//拼接条件
    $where .= " and `endtime`<='$end'";
    }

    $yuList = yii::$app->db->createCommand("select m.id,code,username,begintime,zuowei,move from yuyue as m inner join dingdan as o on m.uid=o.uid where $where")->queryAll();
    $count = count($yuList);//取整
    $pagesize = 2;//每页显示条数
    $pagesum=ceil($count/$pagesize);//向上取整
    $page=isset($_GET['page'])?$_GET['page']:1;//页数的取值
    $start=($page-1)*$pagesize;//数据的偏移量
    $data['data'] = yii::$app->db->createCommand("select m.id,code,username,begintime,zuowei,move from yuyue as m inner join dingdan as o on m.uid=o.uid where $where limit $start,$pagesize")->queryAll();//查询数据
    $data['start'] = $start;
    $data['end'] = $end;
    $pre=$page-1 < 1 ? 1 : $page-1;//上一页
    $next = $page+1>$pagesum ? $pagesum:$page+1;//下一页
    $data['str']="<a href='javascript:;' class='p' val='1'>首页</a>&nbsp;&nbsp;<a href='javascript:;' val=".$pre." class='p'>上一页</a>&nbsp;&nbsp;<a href='javascript:;' val=".$next." class='p'>下一页</a>";//页数
    if(yii::$app->request->isAjax){
    echo json_encode($data);
    }else{
    return $this->render('listPage',['str'=>$data['str'],'data'=>$data['data']]);
    }
    }

    //前台ajax
    //下一页
    $(document).on('click','.p', function () {
    var start = $(".start").val();
    if(start==''){
    start='';
    }
    var end = $(".end").val();
    if(end==''){
    end='';
    }
    p = $(this).attr('val');
    var str="";
    $.ajax({
    type: "GET",
    url: "<?php echo Yii::$app->urlManager->createUrl('yuyue/yulist')?>",
    data: {page:p,start:start,end:end},
    dataType : "json",//数据类型为jsonp
    success: function(msg){
    str+="<table border='1' id='box'>"+
    "<th>预约号</th><th>预约人</th><th>预约时间</th><th>预约座位</th><th>预约电影</th>";
    for(var i in msg['data']){
    str+="<tr><td><input type='hidden' name='eid' value="+msg['data'][i]['id']+" />"+msg['data'][i]['code']+"</td><td>"+msg['data'][i]['username']+"</td><td>"+msg['data'][i]['begintime']+"</td> <td>"+msg['data'][i]['zuowei']+"</td><td>"+msg['data'][i]['move']+"</td></tr>";
    }
    $("#box").html(str);
    $(".page_").html(msg['str']);
    $(".start").html(msg['start']);
    $(".end").html(msg['end']);
    }
    });
    });
    //搜索
    $(".but").click(function () {
    var p=1;
    var start = $(".start").val();
    if(start==''){
    start='';
    }
    var end = $(".end").val();
    if(end==''){
    end='';
    }
    var str="";
    $.ajax({
    type: "GET",
    url: "<?php echo Yii::$app->urlManager->createUrl('yuyue/yulist')?>",
    data: {start:start,end:end,page:p},
    dataType : "json",//数据类型为jsonp
    success: function(msg){
    str+="<table border='1' id='box'>"+
    "<th>预约号</th><th>预约人</th><th>预约时间</th><th>预约座位</th><th>预约电影</th>";
    for(var i in msg['data']){
    str+="<tr><td><input type='hidden' name='eid' value="+msg['data'][i]['id']+" />"+msg['data'][i]['code']+"</td><td>"+msg['data'][i]['username']+"</td><td>"+msg['data'][i]['begintime']+"</td> <td>"+msg['data'][i]['zuowei']+"</td><td>"+msg['data'][i]['move']+"</td></tr>";
    }
    $("#box").html(str);
    $(".page_").html(msg['str']);
    $(".start").html(msg['start']);
    $(".end").html(msg['end']);
    }
    });
    });

  • 相关阅读:
    Shell 中引用符号的名称及意义
    查看该目录下有几个文件夹几个文件的shell代码
    Linux下find 命令用法详解+实例
    Linux中echo的用法
    man help
    《鸟哥的linux私房菜》关于数据流重导向
    linux开机自动加载服务设置
    Shell调试技术总结(二)
    Shell中关于if,case,for,while等的总结
    硬盘的分区
  • 原文地址:https://www.cnblogs.com/zhanghuilong/p/6480316.html
Copyright © 2020-2023  润新知