This article mainly introduces about Thinkphp3.2.3 search, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
Front-end code :
<form action="{:U('Ginseng/index')}" method="post" id="form_search"> <p class="sleft"> <input type="text" placeholder="请输入证书编号搜索" value="" class="search-input" name="keyword" /> <a id="search" href="javascript:;" onclick="searchSo();" class="sch-btn"> <i class="btn-search"></i> </a> </p> </form>
Jquery code:
<script> function searchSo(){ var url = $('#form_search').attr('action'); var str = $('input[ name = keyword]').val(); var query = 'keyword='+str.replace(/(^\s*)|(\s*$)/g,""); if( url.indexOf('?')>0 ){ url += '&' + query; }else{ url += '?' + query; } window.location.href = url; } </script>
Backend PHP controller code:
public function index(){ $keyword = I('keyword'); $M = M('GinsengResult'); if($keyword!== ''){ $where = []; if($keyword && $keyword != ''){ $where['gin_num'] = array('like','%'.$keyword.'%'); } $count = $M->where($where)->count(); $Page = new \Think\Page($count,1); foreach($where as $key=>$val) { $Page->parameter[$key] = urlencode($val); } $show = $Page->show(); // 分页显示输出 $p = I ( 'p', 1, 'intval' ); $list = $M->where($where) ->field('id,gin_num_thumb,gin_num,publisher,create_time') ->order('article_create_time','DESC') ->page($p.',1') ->select(); }else{ $list = $M ->field('id,gin_num_thumb,gin_num,publisher,create_time') ->order('article_create_time','DESC') ->page($p.',1') ->select(); } $this->assign('list',$list); $this->assign('page',$show); // 赋值分页输出 $this->display(); // 输出模板 }
Related recommendations:
thinkphp3.2.3 complete paging example
##thinkphp3.2.3 registration and uploading pictures
The above is the detailed content of About Thinkphp3.2.3 Search. For more information, please follow other related articles on the PHP Chinese website!