PHP search and query function implementation, php search and query function
Today, I encountered a problem: when I used the "Search" function, I couldn't query it after I entered the query conditions.
What I am doing is to display the content in the package of the data table on the homepage, but there is a condition that the content displayed on the homepage must also be: field status = 0, data with printing = 0 can be displayed on the homepage list.
There is a "Search" function on the page. after entering the conditions, the search will be performed according to the conditions.
For a general search, you only need to give:
$ 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 = '';} of the number of data entries displayed on the page '';} else {$ _ list = $ this-> Model-> where ($ map)-> limit ($ post_data ['first']. ','. $ post_data ['rows '])-> select ();}
Then, write a _ search ():
For example:
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.
However, when searching, make sure that the data in the field status = 0 and printing = 0 is searched.
I 've been wondering where to add this restriction. After trying and querying, you will know. The restrictions can be added directly to the SQL statement (the following is red ). (When I tried it myself, I kept adding conditions in the blue area below, so I tried and tried again and again !)
$map=array();$map=$this->_search();$total = $this->Model->where ($map)->where(array('status' =>0,'print_status'=>0))->count();if ($total == 0) {$_list = '';} else {$_list = $this->Model->where ($map)->where(array('status' =>0,'print_status'=>0))->limit( $post_data ['first'] . ',' . $post_data ['rows'] )->select();}
The above section describes how to implement the PHP search and query function. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!