zoukankan      html  css  js  c++  java
  • ajajx 搜索加分页

    <!DOCTYPE html>
    <html>
    <head>
    <title>搜索加分页</title>
    </head>
    <body>
    <div id="box">

    时间<input type="text" name="stime" class="stime" style="50px">-<input type="text" name="etime" class="etime" style="50px">
    用户名 <input type="text" name="name" class="name" style="50px">
    <button id="search">搜索</button>

    <table border="1">
    <tr>
    <td>id</td>
    <td>用户名</td>
    <td>电话</td>
    <td>时间</td>
    <td>操作</td>
    </tr>
    <tbody id="tbody">
    <foreach name="data" item="val">
    <tr>
    <td>{$val.id}</td>
    <td>{$val.name}</td>
    <td>{$val.phone}</td>
    <td>{:date('Y-m-d H:i:s',$val['add_time'])}</td>
    <td><button class="del" id="{$val.id}">删除</button></td>
    </tr>
    </foreach>
    </tbody>
    </table>
    <div class="list-page">{$page} </div>
    </div>
    </body>
    </html>

    <script type="text/javascript" src='__PUBLIC__/jquery.js'></script>

    <script type="text/javascript">

    var obj = Object();
    //删除
    $('#box').delegate('.del','click',function(){
    obj['id'] = $(this).attr('id');

    var p = $('#nowPage').html();

    getAjax(p ,"{:U('Index/del')}");

    })


    //分页
    $('#box').delegate('.page','click',function(){
    var p = $(this).attr('opt');

    getAjax(p);
    })

    //搜索
    $('#search').click(function(){
    obj['stime']=$('.stime').val();
    obj['etime']=$('.etime').val();
    obj['name']=$('.name').val();

    getAjax();

    })
    //ajax
    function getAjax(p = 1,fun = '{:U("Index/fenye")}'){
    var str='';
    $.each( obj, function(k, v){
    str+=k+'='+v+'&';
    });
    $.ajax({
    type: "GET",
    url:fun,
    data: str+"p="+p,
    dataType:'json',
    success: function(msg){
    var str ='';
    $.each(msg['data'],function(k,v){
    str+='<tr>';
    str+='<td>'+v.id+'</td>';
    str+='<td>'+v.name+'</td>';
    str+='<td>'+v.phone+'</td>';
    str+='<td><button class="del" id="'+v.id+'">删除</button></td>';
    str+='</tr>';
    })

    $('#tbody').html(str);
    $('.list-page').html(msg['page']);

    }
    });
    }
    </script>

    controller

    //分页加搜索的展示

    function show(){

    //echo $time = time();die;
    //echo date('Y-m-d H:i:s',time());
    $this->fenye(false);

    }


    //分页
    function fenye($display = ture){
    $where = $this->_where();
    //总条数
    $count = M('admin')->where($where)->count();

    //实例化分页类
    $page = new OrgUtilPage($count);
    $Pagestr = $page->getPage();

    //查询所有数据
    $data = M('admin')->limit($page->limit,$page->page_num)
    ->where($where)->select();



    if($display){
    $datainfo['data']=$data;
    $datainfo['page']=$Pagestr;
    // print_r($datainfo);
    echo json_encode($datainfo);
    }else{
    $this->assign('data',$data);
    $this->assign('page',$Pagestr);
    $this->display('show');
    }
    }

    //条件
    function _where(){
    $where = I('get.');
    $post = array('1=1');

    //开始时间
    if(!empty($where['stime'])){
    $post[] = 'add_time >='.strtotime($where['stime']);
    }

    //结束时间
    if(!empty($where['etime'])){
    $post[] = 'add_time <='.strtotime($where['etime']);
    }
    //用户名
    if(!empty($where['name'])){
    $post[] = 'name = "'.$where['name'].'"';
    }
    $where = implode(' and ',$post);

    // //房间号
    // if(!empty($where['r_num'])){
    // $post[] = 'r_num like "%'.$where['r_num'].'%"';
    // }

    // //价格
    // if(!empty($where['cheap'])){
    // $post[] = 'price >='.$where['cheap'];
    // }
    // //价格
    // if(!empty($where['heigh'])){
    // $post[] = 'price <='.$where['heigh'];
    // }

    return $where;

    }

    //删除
    function del(){
    $id = I('get.id');
    //echo $id;die;
    $res = M('admin')->delete($id);
    if($res){
    $this->fenye();
    }
    }

  • 相关阅读:
    3、Linux知识点/dos基础命令
    2、进制转换
    1、软件测试基础####################################################
    50.React跳转路由传参3种方法和区别
    49.react中使用less
    48.vue-awesome-swipe使用
    47、安装node-sass后运行报错
    46、VUE + JS 面试宝典
    45、导航钩子函数中使用next()和next('指定路径')的区别:
    44、css实现水波纹效果
  • 原文地址:https://www.cnblogs.com/lixiaomingtongxue/p/7891473.html
Copyright © 2011-2022 走看看