search

Home  >  Q&A  >  body text

Thinkphp3 count() method must add fields?

 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

SanysSanys1350 days ago1177

reply all(2)I'll reply

  • 查无此人

    查无此人2021-03-26 16:03:31

    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
    0
  • Siméon

    Hello teacher, can you share the PHP public method library?

    Siméon · 2021-04-02 00:07:35
  • Cancelreply