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

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

藏色散人
藏色散人forward
2021-03-23 17:33:203086browse

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();

2. Pay the query result to the front desk

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

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!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete