Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of keeping conditional pagination in Thinkphp

2025-02-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "the method of keeping conditional pagination in Thinkphp". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

When doing a search query, I suddenly found that the paging code used on the home page had an error when using the search page, and the paging code on the first page (marked start and end in the code as paging code)

The copy code is as follows:

Public function index () {

$res=D ('Info'); / / instantiate the Data data object

/ * start*/

Import ('ORG.Util.Page'); / / Import paging classes

$count= $res- > count (); / / query the total number of records that meet the requirements

$Page = new Page ($count,3); / / Total number of records passed in the instantiated paging class (another parameter is the number of custom pages)

/ / $Page- > rollPage = 3ramp / by default, the number of pages displayed on the page is 5 and can be modified

$show= $Page- > show (); / / pagination display output

/ / query paged data

$list = $res- > order ('iid desc')-> limit ($Page- > firstRow.','.$Page- > listRows)-> select ()

/ * end*/

$this- > assign ('list',$list); / / assign dataset

/ * start*/

$this- > assign ('page',$show); / / assign paged output

/ * end*/

$this- > display (); / / output template

}

Search code (the part marked between start and end in the code is the paging code, and the query condition is saved when the paging jump is annotated). The following two methods can save the condition (it is not clear whether this is a written specification), query:

The copy code is as follows:

Public function search () {

$res=D ('Info')

$name=$_REQUEST ['name']

$sear ['name'] = array (' like','%'.$name.'%')

/ * start*/

Import ('ORG.Util.Page'); / / Import paging classes

$count=$res- > where ($sear)-> count (); / / query the number of entries

$Page=new Page ($count,2); / / instantiate the paging function

/ * end*/

/ / Save query conditions when paging redirects

Foreach ($sear as $key= > $val) {

$Page- > parameter. = "$key=" .urlencode ($name). "&"; / / assign to Page

}

/ * start*/

$show=$Page- > show (); / / pagination display output

/ / query paged 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 is as follows:

Foreach ($sear as $key= > $val) {

$Page- > parameter. = "$key=" .urlencode ($name). "&"; / / assign to Page

}

"$key=" .urlencode ($name). "&"

The $name here corresponds to the extracted value of $name=$_REQUEST ['name'];.

The second kind:

The copy code is as follows:

Public function search () {

$res=D ('Info')

$name=$_REQUEST ['name']

$sear ['name'] = array (' like','%'.$name.'%')

Import ('ORG.Util.Page'); / / Import paging classes

$count=$res- > where ($sear)-> count (); / / query the number of entries

$Page=new Page ($count,2); / / instantiate the paging function

/ / guarantee the query conditions when paging to jump

Foreach ($sear as $key= > $val) {

$Page- > parameter. = "$key=" .urlencode ($val [1]).'&'

}

$show=$Page- > show (); / / pagination display output

/ / query paged data

$val=$res- > where ($sear)-> limit ($Page- > firstRow.','.$Page- > listRows)-> select ()

$this- > assign ('search',$val)

$this- > assign ('page',$show)

$this- > display ()

}

I use $val [1] because $sear is an array, and $val [1] corresponds to the condition I'm looking for, so I can keep the condition for paging.

This is the end of the content of "how to keep conditional pagination in Thinkphp". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report