PHP Search Query function implementation _php instance

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.