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!

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.