当前位置:Gxlcms > PHP教程 > 关于Thinkphp3.2.3搜索

关于Thinkphp3.2.3搜索

时间:2021-07-01 10:21:17 帮助过:21人阅读

这篇文章主要介绍了关于Thinkphp3.2.3 搜索,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

前端代码

<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 代码:

<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>

后端PHP 控制器代码:

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(); // 输出模板 }

相关推荐:

thinkphp3.2.3分页完整实例

thinkphp3.2.3注册上传图片

以上就是关于Thinkphp3.2.3 搜索的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行