【问题标题】:Count query returning the same result wheather condition matches or not计数查询返回相同的结果无论条件匹配与否
【发布时间】:2016-02-16 07:14:33
【问题描述】:

我是 cakephp 3.2 的新手。我根据 cakephp 书使用了一些查询,但我没有得到有效的结果。我已经发布了下面的代码。这里我想使用特定条件从数据库中计算一些记录。但它每次返回 1 ,无论记录是否存在。

  $query = $this->Users->find('all')
                    ->where(['Users.email' => $user->email]);
            $emaildata = $query->select(['count' => $query->func()->count('*')]);
            echo $conter = count($emaildata);//alaways returns 1

请告诉我,我做错了什么吗?提前谢谢你。

【问题讨论】:

    标签: count cakephp-3.0 cakephp-3.x


    【解决方案1】:

    试试这个

    echo $counter = $emaildata->count();exit;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      • 2013-08-30
      • 2016-02-22
      • 2015-01-13
      相关资源
      最近更新 更多