Home > Backend Development > PHP Tutorial > About Thinkphp3.2.3 Search

About Thinkphp3.2.3 Search

不言
Release: 2023-03-25 08:34:01
Original
1775 people have browsed it

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(&#39;Ginseng/index&#39;)}" 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>
Copy after login

Jquery code:

<script>
  function searchSo(){
  	    var url = $(&#39;#form_search&#39;).attr(&#39;action&#39;);
        var str = $(&#39;input[ name = keyword]&#39;).val();
        var query  = &#39;keyword=&#39;+str.replace(/(^\s*)|(\s*$)/g,"");
        if( url.indexOf(&#39;?&#39;)>0 ){
            url += &#39;&&#39; + query;
        }else{
            url += &#39;?&#39; + query;
        }
        window.location.href = url;
  }


</script>
Copy after login

Backend PHP controller code:

public function index(){
			
		$keyword = I(&#39;keyword&#39;);
		$M = M(&#39;GinsengResult&#39;);
		if($keyword!== &#39;&#39;){
			
	    	$where = [];
	    	if($keyword && $keyword != &#39;&#39;){
	    		$where[&#39;gin_num&#39;]  = array(&#39;like&#39;,&#39;%&#39;.$keyword.&#39;%&#39;);
	    	}
	    	$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 ( &#39;p&#39;, 1, &#39;intval&#39; );
	    	$list = $M->where($where)
	    	      ->field(&#39;id,gin_num_thumb,gin_num,publisher,create_time&#39;)
			      ->order(&#39;article_create_time&#39;,&#39;DESC&#39;)
			      ->page($p.&#39;,1&#39;)
			      ->select();
			      
		}else{
			$list = $M
	    	      ->field(&#39;id,gin_num_thumb,gin_num,publisher,create_time&#39;)
			      ->order(&#39;article_create_time&#39;,&#39;DESC&#39;)
			      ->page($p.&#39;,1&#39;)
			      ->select();
		}
    	
			$this->assign(&#39;list&#39;,$list);  
			$this->assign(&#39;page&#39;,$show);        // 赋值分页输出
			$this->display();                   // 输出模板      
		
	}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template