Hey developers -
I’m building a controller that needs to run through the results of a mySQL query and append a few extra fields based on what the row contains. Basically I’m just running a loop to keep it out of the template and make things more portable.
However, I’m not figuring out how to add info back to the main array generated from the mySQL query.
The goal is to leave an array intact at the end with all of the results plus the new fields on each row so I can open it up in a corresponding template, loop through them and display it all.
Code:
$id = 0;
$activities = $this->activity_model->getActivity();
foreach($activities->result_array() as $activity){
$activities[$id]['show'] = 0;
...
}
This produces the error: Cannot use object of type CI_DB_mysql_result as array in…
Simply appending via $activity[‘show’]=0; works fine of course but does not carry through back to the main array and into the template.
Help?