Home > PHP Framework > ThinkPHP > body text

What is the usage of count in thinkphp

WBOY
Release: 2022-02-18 15:12:41
Original
5162 people have browsed it

In thinkphp, the count method is a statistical query method, used to count the number of data tables or data records. The returned result is the counted number of characters. The syntax is "$model -> [where() - > ] count();".

What is the usage of count in thinkphp

The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.

What is the usage of count in thinkphp

Statistical query methods in ThinkPHP

In ThinkPHP, the system provides the use of the following query methods, which is convenient for later needs Use of statistics.

count() represents the total number of records in the query table

count method

Syntax:

$model -> [where() -> ] count();
Copy after login

Case: Query the department table total.

    //count方法
    public function test(){
        //实例化模型
        $model = M('Dept');
        //count方法
        $result = $model -> count();
        //打印
        dump($result);
 
    }
Copy after login

Display results:

What is the usage of count in thinkphp

The return value is in the form of characters.

Results in sql tracking information:

What is the usage of count in thinkphp

Information in database:

What is the usage of count in thinkphp

Recommended learning : "PHP Video Tutorial"

The above is the detailed content of What is the usage of count in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!