搜索: 按群名称搜索 按群号码搜索
ajax提交
JS部分:
//搜索 $(document).on("click","#search",function(){ if($("#sv").val().trim() == ''){ layer.alert("搜索条件不能为空"); return false; } $.get( "{:url('index/rooms_chat')}", {k:$("#sk").val(),v:$("#sv").val()}, function(d){ // console.log(d); $('html').html(d); } ); });
PHP 方法:
public function rooms_chat(Request $request){ //获取所有的群组 if(null != $request->get('v')){ //带搜索条件的页面 $k = $request->get('k'); $v = $request->get('v'); $rooms = Db::name('room') ->field("room_id,room_name ,r_id ") ->order('r_id','desc') ->where($k,'like',"%".$v."%") ->paginate(3,false,['query'=>$request->param()]); if($rooms->isEmpty()){ return view('rooms_chat',['rooms'=>"暂无数据"]); } return view('rooms_chat',['rooms'=>$rooms,'page'=>$rooms]); }else{ //默认打开页面 $rooms = Db::name('room') ->field("`room_id`,`room_name` ,r_id ") ->paginate(3); return view('rooms_chat',['rooms'=>$rooms,'page'=>$rooms]); } }
确保搜索条件分页条件都不会遗漏的关键: paginate(3,false,['query'=>$request->param()]);
还有分页的CSS样式:
/*分页样式*/ .pagination{text-align:center;margin-top:20px;margin-bottom: 20px;} .pagination li{margin:0px 10px; border:1px solid #e6e6e6;padding: 3px 8px;display: inline-block;} .pagination .active{background-color: #009688;;color: #fff;} .pagination .disabled{color:#aaa;}
发表评论: