Php 查找(';计数';)查找(';全部';)组合
我在下面有一个代码来查找所有的学生名单Php 查找(';计数';)查找(';全部';)组合,php,cakephp,Php,Cakephp,我在下面有一个代码来查找所有的学生名单 $fub = $this->Customer->find('all', array('conditions' => array('Customer.customers_types' => 'student'))); 下面我有一个代码来计算尝试测试的学生人数 $totalTests = $this->Customer->Test->find('count', array('conditions' => arr
$fub = $this->Customer->find('all', array('conditions' => array('Customer.customers_types' => 'student')));
下面我有一个代码来计算尝试测试的学生人数
$totalTests = $this->Customer->Test->find('count', array('conditions' => array('Test.customer_id' => $fub['Customer']['id'])));
$this->set('totalTests', $totalTests);
然而,我有不止一个客户是学生。如何使用$fub的结果并将其放入$totalTests条件中,以获得尝试测试的学生总数
$totalTests = $this->Customer->Test->find('count', array('conditions' => array('Test.customer_id' => $fub['Customer']['id'])));
$this->set('totalTests', $totalTests);
调试器::dump($fub)
您可能应该使用[]。它为您跟踪相关项目的计数。在计数查询中,您尝试的条件可能不匹配,并返回空数组
$fub['Customer']['id']
是空的。在进行计数查询之前,首先调试$fub。
我遵循的方法是设置
$fub['customer']['id']
变成一个变量,就像那样
$f = $fub['customer']['id']
在您的计数查询之前
然后把这个变量放在你的条件下
$totalTests = $this->Customer->Test->find('count', array('conditions' => array('Test.customer_id' => $f)));
试试这个