I've got a function in my model:
public function get_job($lsnumber = FALSE) {
$this->db->join('administrator', 'job.idadministrator = administrator.idadministrator');
$this->db->join('artwork', 'job.idjob = artwork.idjob');
if($lsnumber === FALSE) {
$query = $this->db->get('job');
return $query->result_array();
}
}
Returning this lets me generate a row for each entry in the database using a foreach loop in my view.
Sometimes these rows will have things in common, for example the idjob field as referenced in the join rule.
At the moment, I'm getting an output (from print_r) like this:
Array
(
[idjob] => 1
[lsnumber] => 12345
[custname] => Scott Brown (Customer)
[custemail] => [email protected]
[custcompany] => Customer
[idadministrator] => 1
[complete] => 0
[administratorname] => Scott Brown (Administrator)
[administratoremail] => [email protected]
[administratorjob] => Job
[administratorphone] => 01234 567890
[idartwork] => 1
[filename] => gb-usb1.jpg
[productname] => Bespoke USB Drive
[revision] => 0
[status] => N
)
Array
(
[idjob] => 1
[lsnumber] => 12345
[custname] => Scott Brown (Customer)
[custemail] => [email protected]
[custcompany] => LSi (Customer)
[idadministrator] => 1
[complete] => 0
[administratorname] => Scott Brown (Administrator)
[administratoremail] => [email protected]
[administratorjob] => Job
[administratorphone] => 01234 567890
[idartwork] => 2
[filename] => pa17.jpg
[productname] => Notebooks
[revision] => 0
[status] => Y
)
However, I'd like the array to be grouped and multidimensional, something like this:
Array
(
[idjob] => 1
[lsnumber] => 12345
[custname] => Scott Brown (Customer)
[custemail] => [email protected]
[custcompany] => Customer
[idadministrator] => 1
[complete] => 0
[administratorname] => Scott Brown (Administrator)
[administratoremail] => [email protected]
[administratorjob] => Job
[administratorphone] => 01234 567890
[artwork][0] => Array
(
[idartwork] => 1
[filename] => gb-usb1.jpg
[productname] => Bespoke USB Drive
[revision] => 0
[status] => N
)
[artwork][1] => Array
(
[idartwork] => 2
[filename] => pa17.jpg
[productname] => Notebooks
[revision] => 0
[status] => Y
)
)
I want to be able to group it by the idjob and build a sub-array of all the artworks joined to it.
I've tried all kinds of thing: array_chunk(), group by, all sorts.