Home > PHP Framework > ThinkPHP > How to count the number of records under specified conditions in ThinkPHP5

How to count the number of records under specified conditions in ThinkPHP5

藏色散人
Release: 2021-03-24 09:03:16
forward
3111 people have browsed it

The following tutorial column will introduce to you the method of counting the number of records under specified conditions in ThinkPHP5. I hope it will be helpful to friends in need! ThinkPHP5 counts the number of records under specified conditions

Description

ThinkPHP5 counts the number of records under specified conditions

Application examples

Statistics on the number of orders

Solution

Use "aggregation query". Reference documentation

Backend code

Use model.

1. Query statement

$recordNum = \app\index\Model\Reservation::where('username','=',session('username'))->count();
Copy after login

2. Pay the query result to the front desk

$this->assign([
    'recordNum'=>$recordNum,
]);
Copy after login
How to count the number of records under specified conditions in ThinkPHP5Front-end code
<p>A total of {$recordNum}</p>
Copy after login

Result

How to count the number of records under specified conditions in ThinkPHP5

How to count the number of records under specified conditions in ThinkPHP5##Related recommendations:

The latest 10 thinkphp video tutorials

The above is the detailed content of How to count the number of records under specified conditions in ThinkPHP5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template