Thinkphp3 count() method must add fields?
Sanys
Sanys 2021-03-20 17:25:41
0
2
1166
 public function showList(){
        $model =D('article');
        $total=$model->count('id');
         $this->assign('total',$total);// 赋值分页输出
        $this->display(); // 输出模板
     }//showlist end

The count here must be added with the id parameter, otherwise an error will be reported. May I ask why?

The error is as follows:

1054:Unknown column '*' in 'field list' [SQL statement]: SELECT COUNT(`*`) AS tp_count FROM `xh_article` LIMIT 1

The database structure is as follows Shown:

微信图片_20210320172548.png

Sanys
Sanys

reply all(1)
欧阳

What version is this 3.? count() can be used without passing a value. If an error is reported, look for the source code of the count method and look at the source code.

Don’t worry too much about this small problem, and your version is too low. Study the new version more and keep up with the progress

  • reply Hello teacher, can you share the PHP public method library?
    Siméon author 2021-04-02 00:07:35
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template