Welcome Guest, Not a member yet? Register   Sign In
Multi Dimensional array issue
#3

[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
     )
    )
  
   )
  
  )


Messages In This Thread
Multi Dimensional array issue - by El Forum - 11-22-2012, 08:37 AM
Multi Dimensional array issue - by El Forum - 11-22-2012, 03:16 PM
Multi Dimensional array issue - by El Forum - 11-23-2012, 04:11 AM
Multi Dimensional array issue - by El Forum - 11-23-2012, 07:47 AM
Multi Dimensional array issue - by El Forum - 11-23-2012, 08:24 AM
Multi Dimensional array issue - by El Forum - 11-23-2012, 09:04 AM
Multi Dimensional array issue - by El Forum - 11-23-2012, 03:59 PM
Multi Dimensional array issue - by El Forum - 11-24-2012, 10:19 AM
Multi Dimensional array issue - by El Forum - 11-24-2012, 10:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB