php - Codeigniter - use query result in another query -
in controller have list of results query (up 10 rows or so). trying use results of query use in another. example, first query pulls out 'agency_id' (the data wish use in next query)
controller:
$data['list_report'] = $this->reports_model->filteredreport(); $data['area_data'] = $this->reports_model->getareadatareport($data['list_report']); model:
function getareadatareport($data) { $query = $this->db->query('select count(asa.sector_id) area_count, asa.*, ags.sector agencies_sector_association asa, agencies_sector ags agency_id in ('. $data->agency_id .') , asa.agency_id = ags.id group agency_id'); return $query->result(); } i error:
message: trying property of non-object codeigniter model when print_r first query results following.
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 ) ) my question how use agency_id of first statement in next statement array wont return 1 row. result 3 'agency_id' results back, more in future searches.
many can help!
$data array of objects containing 1 object.
replace $data->agency_id $data[0]->agency_id
this give agency_id member variable of object stored @ position [0] in $data array.
assuming have more 1 object in array of results need ids , store them in string use string in query
$id_str = ''; foreach($data $agency) { $id_str .= $agency->agency_id . ', '; } $id_str = rtrim($id_str, ', '); //remove trailing comma , space now replace $data->agency_id in query $id_str
Comments
Post a Comment