0

我有一个下表显示

Task No.    Person            Company           Project Task               Date Tracked Total Time  Comments
14.1    vaish, arpit          ABC-TecHolding    Relaunch Websitnalysis     2013-02-12   19:21:03    
14.2    vaish, arpit          Sugarion          New Opensource Server      2013-02-12   19:21:03    
14.6    vaish, arpit          Sugarion          New Opensource Server      2013-02-12   19:21:03    
5.26    Projectmanager, Paul  ABC-Tec Holding   Relaunch Website           2010-03-13   03:40:16    
5.27    Projectmanager, Paul  ABC-Tec Holding   Relaunch Website           2010-03-12   03:40:16    
5.27    Projectmanager, Paul  ABC-Tec Holding   Relaunch Website           2010-03-13   03:40:16    
8.2     Worker, Willi         Customers ACME    Hosting Data transfer      2010-03-13   00:21:18    
14.2    Worker, Willi         Sugarion          New Opensource Server      2013-02-06   00:21:18    fyhbvghjukjjkhhlhh uuiuijujj jookljh

这是我的 foreach 循环

foreach($result123 as $key=>$task) {
            $time=$this->addtime($task['name'],$range['start'],$range['end']); //to calculate total time per user in time range

            $diff       = $task['estimated']+$task['tracked'];
            $diffSign   = $diff > 0 ? '-' : '+';

            $table->addRow(array(
                'number'    => $task['tasknumber'].' '.$task['id_project'] ,
                'person'=> $task['name'],
                'customer'      => $task['company'],
                'project'       => $task['project'],
                'task'      => $task['task'],
                'date'      => $task['date_tracked'],
                'tracked'   => $task['workload_tracked'],
                'Total_Time'        => $time,
                'comment'=>$task['comment']
            ));

        }

总时间列显示每人跟踪的总时间。我希望每个人只显示一次总时间,而不是每行一次又一次地显示。提前致谢。

4

2 回答 2

0

我就是这样做的(伪代码):

  • 设置一组“已检查”人员
  • Foreach 记录:
  • 人在“已检查”数组中吗?
  • 如果是,请继续。
  • 如果否,则显示总数并将人员添加到“已检查”人员。

在 PHP 中:(如果我做对了)

  $checked = array();

  foreach($result123 as $key=>&$task) {
        $time=$this->addtime($task['name'],$range['start'],$range['end']); //to calculate total time per user in time range

        $diff       = $task['estimated']+$task['tracked'];
        $diffSign   = $diff > 0 ? '-' : '+';

        if (in_array($task['name'],$checked) $time =0;
        else {
              $checked[] = $task['name'];
        }

        $table->addRow(array(
            'number'    => $task['tasknumber'].' '.$task['id_project'] ,
            'person'=> $task['name'],
            'customer'      => $task['company'],
            'project'       => $task['project'],
            'task'      => $task['task'],
            'date'      => $task['date_tracked'],
            'tracked'   => $task['workload_tracked'],
            'Total_Time'        => $time,
            'comment'=>$task['comment']
        ));

    }
于 2013-02-12T06:40:57.813 回答
0
$name = '';

foreach($result123 as $key=>$task) {


if ($name == $task['name']) {
$time = '';
}
elseif ($name != $task['name']) {
$time=$this->addtime($task['name'],$range['start'],$range['end']); 
$name = $task['name'];
}


$diff= $task['estimated']+$task['tracked'];
$diffSign= $diff > 0 ? '-' : '+';

$table->addRow(array(
'number'    => $task['tasknumber'].' '.$task['id_project'] ,
'person'=> $task['name'],
'customer'      => $task['company'],
'project'       => $task['project'],
'task'      => $task['task'],
'date'      => $task['date_tracked'],
'tracked'   => $task['workload_tracked'],
'Total_Time'        => $time,
'comment'=>$task['comment']
));

}

我认为应该这样做。

于 2013-02-12T06:46:57.170 回答