我有一个下面的代码来查找所有的学生名单
$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条件中,以获得尝试测试的学生总数。
调试器::dump($fub);
array(
array(),
array(),
array(),
array(),
array(),
array()
)发布于 2013-01-30 11:12:04
您可能应该使用[ CakePHPs counterCache ]。它会为您跟踪相关项目的数量。
发布于 2013-01-30 12:41:36
在您的计数中,查询您尝试的条件可能不匹配,并返回空数组
$fub['Customer']['id']是空的。在您的count查询之前,首先调试$fub。我遵循的方法是将
$fub['customer']['id']转换为一个变量,就像这样
$f = $fub['customer']['id']在您的count查询和将此变量放入条件之前
$totalTests = $this->Customer->Test->find('count', array('conditions' => array('Test.customer_id' => $f)));试试这个吧。
https://stackoverflow.com/questions/14595667
复制相似问题