[eluser]fasfad[/eluser]
I've made an example, not tested. (should work) ;-)
Code:
$equipment = array();
foreach ($query->result() as $result) {
if(!isset($equipment[$result->eid])) {//if array does not contain the eqid. add information to it;
$equipment[$result->eid]["make"] = $result->make;
$equipment[$result->eid]["model"] = $result->model;
$equipment[$result->eid]["eqid"] = $result->eqid;
$equipment[$result->eid]["projects"] = array(); //we are going to add all hours logged based on date in seperate projects
}
if($result->hours == '' || $result->hours == 0)//no hours to log skip it
continue;
if($result->pid == NULL)
$result->pid = 0; //change NULL pid to 0 so we can use it as project key
if(isset($equipment[$result->eid]["projects"][$result->pid][$result->hdate])) { //date is already set so we ADD the hours to this day
$equipment[$result->eid]["projects"][$result->pid][$result->hdate] += $result->hours;
} else {//date hastn been set so just put hours in this date
$equipment[$result->eid]["projects"][$result->pid][$result->hdate] = $result->hours;
}
}
Your result would be:
Code:
//You should get something like this:
Array
(
[54] => Array
(
[make] => "Titan"
[model] => 23433
[eqid] => "T28"
)
[55] => Array
(
[make] => "Clark"
[model] => "CGP25"
[eqid] => "E8"
[projects] => Array
(
[1] => Array
(
["2012-11-07"] => 5 //If you happen to have another hour-log on this date, it will ad to the current hourlog
["2012-11-08"] => 2
["2012-11-09"] => 4
)
[4] => Array
(
["2012-11-10"] => 5
)
)
)
[56] => Array
(
[make] => "Toyota"
[model] => "Tundra"
[eqid] => "T40"
[projects] => Array
(
[0] => Array //this pid NULL has been changed to 0
(
["2012-11-07"] => 5
)
)
)
)