This time for everyone to bring, the attention matters are what, the following is the actual case, together to see.
The search function here is based primarily on the form get submission implementation.
<form action= "/backend/auditlist" method= "get" > <table class= "Search_tab" > <tr> <th width= > select category:</th> <td> <select Name= "class" > <option value= "" > All </option> @foreach ($category as $c) <option value= "{{$c->id}}" >{{$c->class_name}}< /option> @endforeach </select> </td> <th width= "All" > article title:</th> <!--query keywords-- <td><input type= "text" name= "keywords" placeholder= "article title" ></td> <td><input type= "Submit" Name= "sub" value= "Query" ></td> </tr> </table> </form>
PHP Partial logic
Public Function Article_list () {//echo ' zoule '; exit; test whether the form into the method of everyone to write $shownum = 1; if (array_key_exists (' class ', $_get) | | Array_key_exists (' keywords ', $_get)) {//echo ' 111 '; if ($_get[' class ')} {//article Model Leftjoin table Join query executes $postdata = article::leftjoin (' Category ', function ($joi) based on these fields in both tables N) {$join->on (' article.class_id ', ' = ', ' category.id '); })->select ([' article.id ', ' category.class_name ', ' article.status ', ' article.title_editing ', ' Article.update_ Time '])->where (' article.class_id ', ' = ', $_get[' class '))->orderby (' Release_time ', ' desc ')->paginate ($ Shownum); }elseif ($_get[' keywords ')) {$postdata = Article::leftjoin (' Category ', function ($join) {$join->on (' Article.cla ss_id ', ' = ', ' category.id '); })->select ([' article.id ', ' category.class_name ', ' article.status ', ' article.title_editing ', ' Article.update_ Time '])->where (' article.title_editing ', ' = ', $_get[' keywords '])->orderby (' Release_time ', ' desc ') Paginate ($shownum); }else{$pOstdata = article::leftjoin (' Category ', function ($join) {$join->on (' article.class_id ', ' = ', ' category.id '); })->select ([' article.id ', ' category.class_name ', ' article.status ', ' article.title_editing ', ' Article.update_ Time '])->orderby (' Release_time ', ' desc ')->paginate ($shownum); }}else{//echo ' 2222 '; $postdata = article::leftjoin (' Category ', function ($join) {$join->on (' article.class_id ', ' = ', ' category.id '); })->select ([' article.id ', ' category.class_name ', ' article.status ', ' article.title_editing ', ' Article.update_ Time '])->orderby (' Release_time ', ' desc ')->paginate ($shownum); }//The category ID is not the parent id $category = db::table (' category ')->where (' parent_id ', '! = ', ' 0 ')->get (); Render the page pass parameter return view (' Backend.article_list ', [' postdata ' = ' $postdata, ' shownum ' = ' $shownum, ' category ' =>$ Category]);}
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
PHP to determine whether to open or open the browser
Summarize some MySQL traps