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
Front-end code<p>A total of {$recordNum}</p>
Copy after login
Result
##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!