Today we have a problem: when you do a "search" function, you cannot query after you enter the query criteria.
What I do is to display the contents of the datasheet package in the home page, but there is a condition that the content displayed on the front page must also be: Field status=0, and printing=0 data can be displayed in the first page list.
There is a "search" function on the page, and the criteria will be queried when the condition is entered.
General search words, as long as the first page display list Method index () to one:
$map =array ();//Initialize query condition $map= $this->_search ();//Call Query method $total = $this->model->where ($map)->count (); This is primarily used to calculate if ($total = = 0) of the number of data bars displayed on the page {$_list = ';} else {$_list = $this->model->where ($map)->limit ($post _data [' first ']. ',' . $post _data [' Rows '])->select ();}
Then, just 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.
However, I do this, while searching, also make sure to search in the field status=0, and printing=0 the data.
I've been thinking about where this restriction should be added. A variety of attempts and inquiries before they are known. The restrictions are added directly to the SQL statement (red places below). I have been in the following blue places to add conditions, try repeatedly defeated! )
$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)->whe Re (array (' status ' =>0, ' Print_status ' =>0))->limit ($post _data [' first ']. ',' . $post _data [' Rows '])->select ();}
The above is the PHP search query features detailed introduction and instance code content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!