ThinkPHP6 paging solution with search conditions
In ThinkPHP6, it is not difficult to implement paging, and it is not difficult to implement search, but searching with search conditions stumps many people. In the same situation, we moved the tp5 code and found that it did not work. So how to solve the paging with search conditions in ThinkPHP6?
Let’s look at the specific scenario. I searched for a keyword and selected a category to search and filter articles.
1. Find the problem
First of all, let’s take a look at the first page with search conditions:
Then let’s look at the second page:
Those who are careful will find that there is no URL in the second and third pages. With search criteria.
2. How to solve it:
The key to the problem has been found, so how to solve it? Let’s first go to the official website manual and look for it:
In the manual, there is a query item that is responsible for passing extra parameters in the url, so it will be easy to handle.
Look at the code directly:
$where=[];//筛选条件数组 if(input('cate_id')){ $where[] = [ ['a.cate_id', '=', $cate_id], ]; } if(input('searchkey')){ $where[] = [ ['title', 'like', '%'.$searchkey.'%'], ]; } $archivesData=Db::name('archives')->alias('a')-> field('a.id,a.title,a.listorder,b.cate_name,a.time')-> join('category b','a.cate_id=b.id')-> where($where)-> order('a.listorder asc')->//小到大 order('a.id DESC')->//大-》小 paginate([ 'list_rows'=> 3,//每页数量 'query' => request()->param(), ]);
In this way, we have perfectly solved the problem of "ThinkPHP6 paging with search conditions". In fact, don't be afraid if you encounter problems. Let's take a closer look at the manual first. Maybe it can solve the problems we encounter.
【Related recommendations】
1. 【Dry information】ThinkPHP6 docking WeChat scan code to log in
2. Using factory mode to implement Thinkphp6.0 access to Alibaba Cloud SMS
The above is the detailed content of ThinkPHP6 paging solution with search conditions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

How to use JavaScript to implement table paging function? With the development of the Internet, more and more websites use tables to display data. In some cases where the amount of data is large, the data needs to be displayed in pages to improve user experience. This article will introduce how to use JavaScript to implement table paging function and provide specific code examples. 1. HTML structure First, we need to prepare an HTML structure to host tables and paging buttons. We can use <tab

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.
