I’m having issues adding a “sub result” to a result in Codeigniter. Not sure how to add to this object.
$result->{$record_id}->threads = $threads;
should equal something like this
$result->1->threads = $threads;
but I can’t get it to work… I’m not new to OOP but this is the first I’ve tried to do this.
<?php
function get() {
$this->db->select(array(
'record_id', 'record_data', 'record_date',
));
$this->db->from('records');
$sql = $this->db->get();
$records = $sql->result();
foreach($records as $record){
$record_id = $record->record_id;
$this->db->select(array(
'thread_id', 'thread_parent', 'thread_data', 'thread_date',
));
$this->db->from('records_thread');
$this->db->where(array(
'thread_recordid' => $record_id,
));
$sql = $this->db->get();
$threads = $sql->result();
# this is where i'm having issues \/
$records->{$record_id}->threads = $threads;
}
return $records;
}
?>
I don’t want to use arrays and it’s easier to use this data on the view file.
I think you just need:
EDIT:
You just need to assign the reference in your foreach (note the
&next to$record):