[eluser]Unknown[/eluser]
Hello everyone,
I'm new to CodeIgniter and like it very much. It seems to be the perfect lightweight framework to use it as a base.
My question is about the Active Record Pattern. I'm working on a function that reads data from the database und updates the timestamps of the loaded data. My code looks like this:
Code:
// load data from database
$this->db->where($where);
$query = $this->db->get('table');
$data = $query->result();
if(is_array($data)) {
$ids = FALSE;
// build new array of ids
foreach($data as $entry) {
$ids[] = $entry->id;
}
// update data with array
$this->db->where_in('id', $ids);
$this->db->update('table');
return $data;
}
I was wondering if I'm missing something to shorten the 'foreach' part a bit and maybe don't need to set up a new array for this update part. Like a helper-function or something I don't know about the Active Recored Class that makes it easier to gather the IDs of the data for the update and doesn't make it look so awkward.
Thank you in advance.
Oliver