zoukankan      html  css  js  c++  java
  • 源码分页搜索公用

    //前台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']){//for(var i=0;i<msg.length;i++) {
    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']);
    }
    });
    });

    //控制器
    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']]);
    }
    }

    $(document).on('change','#channelfather',function () {
    var channelval=$('#channelfather').val();
    $.ajax({
    type: "POST",
    url: "/stat/channelson",
    data: "channelint="+channelval,
    dataType: 'json',
    success: function(msg){
    if(msg==''){
    var channeldata='<select class="form-control" id="channelson" name="channelson" size="1"><option value="">无子渠道</option></select>';
    }
    else{
    // var channeldata='<select class="form-control" id="channelson" name="channelson" size="1"><option value="">请选择子渠道</option>';
    // for(var i=0;i<msg.length;i++) {
    // channeldata+='<option value="'+msg[i].cid+'">'+msg[i].promote_name+'</option>';
    // }
    // channeldata+='</select>';
    channeldata=sonchannel(msg);

    }
    $('#channelson').html(channeldata);
    }
    });
    });
    function sonchannel(msg) {

    var channeldata='<select class="form-control" id="channelson" name="channelson" size="1"><option value="">请选择子渠道</option>';
    for(var i=0;i<msg.length;i++) {
    channeldata+='<option value="'+msg[i].cid+'">'+msg[i].promote_name+'</option>';
    }
    channeldata+='</select>';
    return channeldata;
    }
  • 相关阅读:
    centos8 安装vmware需要的内核头文件 kernel-headers.
    centos7开启ssh服务
    systemctl命令的使用及服务状态的查看
    centos WPS 字体安装
    CentOS8 使用 aliyun 阿里云 镜像站点的方法
    CentOS提示::unknown filesystem type 'ntfs'自动挂载NTFS分区的U盘或者移动硬盘
    Aria2 Centos8 安装配置
    centos7 更新Firefox版本
    线程内容详解
    进程池、进程池和多进程的性能测试、进程池的其他机制、进程池的回调函数
  • 原文地址:https://www.cnblogs.com/zhanghuilong/p/6481023.html
Copyright © 2011-2022 走看看