In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to achieve search results on php. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Php to achieve search results: 1, initialize the query conditions; 2, call the query method; 3, calculate the number of data displayed on the page; 4, in the set "search" menu, call the "protected function _ search () {...}" search method.
This article operating environment: Windows7 system, PHP7.4 version, Dell G3 computer.
The implementation of PHP search and query function:
Today encountered a problem: when doing the "search" function, the query can not be queried after entering the query criteria.
What I do is to display the contents of the data table package on the home page, but there is a condition that the content displayed on the home page must also be: field status=0, and the data of printing=0 can be displayed in the list on the home page.
There is a "search" function on the page, and after entering the criteria, the query will be made according to the conditions.
For a general search, just give one in the home page display list method index ():
$map=array (); / / initialize the query condition $map=$this- > _ search (); / / call the query method $total = $this- > Model- > where ($map)-> count (); / / this is mainly used to calculate the if ($total = = 0) {$_ list =';} else {$_ list = $this- > Model- > where ($map)-> limit ($post_data ['first']). ','. $post_data ['rows'])-> select ();}
Then, write a _ search ():
Such as:
Protected function _ search () {$map = array (); $post_data = I ('post.'); if ($post_data [' packageid']! ='') {$map ['packageid'] = array (' like','%'. $post_data ['packageid']. '%');} return $map;}
Finally, in the set search menu, call this search method.
But what I'm doing is that while searching, make sure you search in the data in the field status=0 and printing=0.
I've been thinking about where this restriction should be added. I didn't know until after various attempts and inquiries. Constraints can be added directly to the SQL statement (such as the red below). When I try by myself, I always add conditions in the following blue places, and I fail again and again! )
$map=array (); $map=$this- > _ search (); $total = $this- > Model- > where ($map)-> where (array ('status'= > 0 count printstatuses = > 0))-> count (); if ($total = = 0) {$_ list =';} else {$_ list = $this- > Model- > where ($map)-> where (array ('status'= > 0) printstatuses = > 0))-> limit ($post_data [' first']. ','. $post_data ['rows'])-> select ();}
This is the end of the article on "how to achieve search results in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.