Today encountered a problem: In doing "search" function, enter the query conditions after the query can not.
I do is the first page shows the contents of the datasheet package, but there is a condition, the content displayed on the first page must also be: Field status=0, and printing=0 data can be displayed in the Home page list.
There is a "search" feature on the page, and when you enter a condition, the query is based on the criteria.
General search words, just in the first page display list Method index () to a:
$map =array ()///Initialize query condition
$map = $this->_search (), or call query method
$total = $this->model->where ($map)-> Count (); This is primarily used to calculate
if ($total = = 0) {
$_list = ';
} else {
$_list = $this->model->where ($map)-& of the page display data Gt;limit ($post _data [' a ']. ',' . $post _data [' Rows '])->select ();
}
Then, it is to 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 "Search" menu set, call this search method.
But, I do this, search at the same time, but also make sure that the field status=0, and printing=0 data to search.
I've been thinking about where this restriction should be added. Various attempts and inquiries were only known. The restriction condition is added directly to the SQL statement (the Red place below). (I try to be the same as the following blue places add conditions, repeated trial and failure!) )
$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 (' status ' =& gt;0, ' Print_status ' =>0)->limit ($post _data [' a ']. ',' . $post _data [' Rows '])->select ();
}
The above is a small set for you to introduce the PHP search query function to achieve, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!