在我的控制器中,我有一个查询结果列表(最多 10 行左右)。我正在尝试使用查询的结果在另一个中使用。例如,第一个查询提取“agency_ID”(我希望在下一个查询中使用的数据)
控制器:
$data['list_report'] = $this->reports_model->filteredReport();
$data['area_data'] = $this->reports_model->getAreaDataReport($data['list_report']);
模型:
function getAreaDataReport($data)
{
$query = $this->db->query('SELECT COUNT(asa.sector_ID) AS area_count, asa.*, ags.sector
FROM agencies_sector_association asa, agencies_sector ags WHERE agency_ID IN ('. $data->agency_ID .')
AND asa.agency_ID = ags.ID
GROUP BY agency_ID');
return $query->result();
}
我收到此错误:
Message: trying to get property of non-object codeigniter model
当我 print_r 第一个查询结果时,我得到以下结果。
Array ( [0] => stdClass Object ( [case_ID] => 1 [reference_ID] => IFSOU001 [ID] => 1 [agency_ID] => 1 [agency_name] => Agency1 [task_ID] => 3 [task] => Domestic violence [outcome_ID] => 3 [outcome] => Protection plan no longer in place [creation_date] => 2012-12-05 ) [1] => stdClass Object ( [case_ID] => 3 [reference_ID] => NEW REFERENCE ID [ID] => 2 [agency_ID] => 1 [agency_name] => Agency1 [task_ID] => 1 [task] => Transport [outcome_ID] => 8 [outcome] => Bespoke needs based assessment received [creation_date] => 2013-05-01 ) [2] => stdClass Object ( [case_ID] => 6 [reference_ID] => REFERENCE ID [ID] => 6 [agency_ID] => 1 [agency_name] => Agency1 [task_ID] => 2 [task] => Counselling [outcome_ID] => 2 [outcome] => Improved school attendance [creation_date] => 2013-05-01 ) )
我的问题是如何在下一个语句中使用第一个语句的 Agency_ID 作为数组,这样它就不会只返回一行。从这个结果中,我得到了 3 个“agency_ID”结果,但在以后的搜索中可能会更多。
非常感谢所有可以提供帮助的人!