In this paper, we describe the method of thinkphp the first page pagination and the search page to maintain the conditional paging when the search is implemented. Share to everyone for your reference. The implementation method is as follows:
When doing a search query suddenly found in the page with the pagination code in the search page using error, home page code (the code labeled Start and end part of the page code)
Copy the Code Code as follows: Public Function index () {
$res =d (' Info ');//Instantiate data Object
/**********start************/
Import (' ORG. Util.page ');//Import page-out class
$count = $res->count ();//query satisfies the required total number of records
$Page = new Page ($count, 3);//Instantiate the total number of incoming records in the paging class (the other parameter is the number of custom pagination bars)
$Page->rollpage = 3;//By default, the number of pages displayed on the page is 5 can be modified
$show = $Page->show ();//pagination display output
Querying for paging data
$list = $res->order (' iid desc ')->limit ($Page->firstrow. ', '. $Page->listrows)->select ();
/**********end************/
$this->assign (' list ', $list);//Assignment Data set
/*********start*************/
$this->assign (' page ', $show);//Assignment Paging output
/*********end*************/
$this->display (); Output template
}
The search code (in the code between start and end is the pagination code, the note labeled page jump to save the query condition), the following two methods can be saved conditions (not clear that is not written specification), query:
Copy the Code Code as follows: Public function search () {
$res =d (' Info ');
$name =$_request[' name '];
$sear [' name '] = Array (' Like ', '% '. $name. ' %');
/*********start*************/
Import (' ORG. Util.page ');//Import page-out class
$count = $res->where ($sear)->count ();//query Data bar number
$Page =new page ($count, 2);//Instantiate paging function
/*********end*************/
Save query conditions when paging jumps
foreach ($sear as $key = = $val) {
$Page->parameter. = "$key =". UrlEncode ($name). " & ";//Assign a value to page
}
/*********start*************/
$show = $Page->show ();//pagination display output
Querying for paging data
$val = $res->where ($sear), $val = $res->where ($sear)->limit ($Page->firstrow. ', '. $Page->listrows) ->select ();
/*********end*************/
$this->assign (' Search ', $val);
/*********start*************/
$this->assign (' page ', $show);
/*********end*************/
$this->display ();
}
Note:
The copy Code code is as follows: foreach ($sear as $key = = $val) {
$Page->parameter. = "$key =". UrlEncode ($name). " & ";//Assign a value to page
}
"$key =". UrlEncode ($name). " & "; The $name in this should be extracted $name =$_request[' name '); Gets the value.
The second type:
Copy the Code Code as follows: Public function search () {
$res =d (' Info ');
$name =$_request[' name '];
$sear [' name '] = Array (' Like ', '% '. $name. ' %');
Import (' ORG. Util.page ');//Import page-out class
$count = $res->where ($sear)->count ();//query Data bar number
$Page =new page ($count, 2);//Instantiate paging function
When paging jumps, guarantee the query condition
foreach ($sear as $key = = $val) {
$Page->parameter. = "$key =". UrlEncode ($val [1]). ' & ';
}
$show = $Page->show ();//pagination display output
Querying for paging data
$val = $res->where ($sear)->limit ($Page->firstrow. ', '. $Page->listrows)->select ();
$this->assign (' Search ', $val);
$this->assign (' page ', $show);
$this->display ();
}
Using $val[1] is because $sear is an array, and $val[1] corresponds to the condition I'm looking for, so I can keep the condition paged.
More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Course" and "thinkphp Common methods Summary"
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.