thinkphp Query (search) criteria in pagination

Source: Internet
Author: User

Parameter property assignment value

For example, to retrieve a user table with a status of 1 (Status=1) and an electronic containing 163 of users, when submitting a form (note that the form is submitted by GET mode), the resulting URL address is roughly the following:

http://www.5idev.com/index.php/Index/search/status/1/email/163

The main code in the search operation is as follows:

Public Function Search () {    $Dao = M ("User");    Constructs the query condition    $condition [' status '] = $_get[' status '];    $condition [' email '] = array (' Like ', "%". $_get[' email '). " %");    Total count    $count = $Dao->where ($condition)->count ();    Import the paging class import    ("ORG. Util.page ");    Instantiate the paging class    $p = new page ($count, ten);    Get query Parameters    $map [' status '] = $_get[' status '];    $map [' email '] = $_get[' email '];    foreach ($map as $key = + $val) {           $p->parameter. = "$key =". UrlEncode ($val). " & ";       }    Pagination Display output    $page = $p->show ();    Current page data query    $list = $Dao->where ($condition)->order (' uid ASC ')->limit ($p->firstrow. ', '. $p listRows)->select ();    Assignment Value    $this->assign (' page ', $page);    $this->assign (' list ', $list);    $this->display ();}

In the page's paging link, you can see that the address (for example, page 2nd) is:

http://www.5idev.com/index.php/Index/search/status/1/email/163?status=1&email=163&p=2

You can see that the status=1&email=163 condition that needs to be retrieved is already included in the paging link. Of course, the actual parsed address should be:

http://www.5idev.com/index.php/Index/search/status/1/email/163/p/2/

This is because the thinkphp paging class is not perfect for handling URLs. To improve on this, see the thinkphp custom paging style and URL.

Incoming parameter parameter

The key to paging with query criteria is to set the parameter property value for the paging class . In addition to assigning values to the Parameter property in the previous example, the parameter parameter can be passed in directly when the class is instantiated, and the results are consistent:

$parameter = ' status= '. UrlEncode ($_get[' status '). ' &email= '. UrlEncode ($_get[' email ');//Add parameter parameter when instantiating a paging class $p = new Page ($count, ten, $parameter);//pagination display output $page = $p ->show ();
Tips

The above example is only used to describe the use of the query condition in the paging, so the retrieved keywords are not processed securely. In actual use, before the query, the user input keywords to do security aspects of processing.

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.