PHP search and query function details and instance code

Source: Internet
Author: User
Today, I encountered a problem: when I used the "search" function, I couldn't query it after I entered the query conditions. What I do 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 status0 and the printing0 data can be displayed in the homepage list. There is a "search" function on the page. after entering the conditions, the search will be performed according to the conditions. A common search problem occurs today: when the "search" function is enabled, the query condition cannot be entered.

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 is a detailed description of the PHP search and query function and the content of the instance code. For more information, see PHP Chinese network (www.php1.cn )!

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.