Trouble appending data to mySQL array results

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?

Can you post the getActivity() method please Ted?

Of course. Simplified significantly as it’s an extensive amount of query logic but only a single action / output method.


function getActivity($user_id,$friends,$limit)
{

$this->db->select('
	activity.user_id,
	activity.friend_id,
	activity.action
');
$this->db->where('action !=', 'facebook');
return $this->db->get('activity', 10);
}

get() is a function from code igniter’s active record database class.

Try this Ted.


return $this->db->get('activity', 10)->result_array();

That did it. Thanks!