之前开贴问过,不过没有能够自己解决,继续提问
这回整理的 应该更明白一些图表的简要说明以及问题说明
1.行驶距离、行驶时间需要进行合计   合计1 应为5.4+5.7+2.9=14.0km 
问题1. 目前的实际情况为5.7+2.9=8.6km2.合计3  
问题2.也就是数据库最后一个读取出来的无法进行合计前两个问题 
我能够知道是由于$last['name']是否等于$row['name']判断而出现的现象    
每回更换$row['name']的时候,由于是不同的,所以统计的时候,行驶距离的合计,所有name的第一项都没有进行合计,
而最后一个$row['name']在做判断时,不会出现不同的,所以没有走到合计的那一步代码中。
不知道应该如何进行更改3.作业时间=出发时间-到达时间 此处无问题4.行驶时间=到达时间(2)-出发时间(1)   如果$last['name']==$row['name'] 那么就
$xingshi=(strtotime($row['arrivetime'])-strtotime($last['gotime']))/60;,如果不等 $xingshi=0;
在表格中输出 echo $xingshi;
问题3.在做行驶时间的统计的时候,这块要如何 分别的进行合计时间的计算  即合计1处为70min,合计2处为63min ,合计3处为20min5.行驶速度  这里的计算应该也没有什么问题
if($xingshi!=0){
echo $row['distance']/($xingshi/60);
}
else{
echo "0";
}6.到达时间、出发时间 应该都是直接从数据库中读取的下面是代码<?php
//进行判断,如何输出的部分代码
$sql="select * from record where officecode='$officecode' and searchtime like '%$riqi%' order by name limit $offset,$Page_size" ;
$result=mysql_query($sql,$link);
$last=array();
while($row=mysql_fetch_array($result)){
if($last){
if($row['name']==$last['name']){
$xingshi=(strtotime($row['arrivetime'])-strtotime($last['gotime']))/60;
$d=$last['distance'];
$sum+=$row['distance'];
$sum1+=$xingshi; //这个肯定是不对的,没有考虑好,如何进行统计
}
else{
$xingshi=0;
?>
      <td colspan="4">合计</td>
      <td bgcolor="#E0EEE"><div align="center"> 
<?php echo $sum."km"; ?> 
</div></td>
<td><?php echo $sum1."min"; ?></td>
<?php
$sum=0;
}}
$last=$row;
?>

解决方案 »

  1.   

    <xmp>
    <?php
    $ar = array(
     array('name' => 1, 'distance' => 5.4, 'arrivetime' => '13:25', 'gotime' => '13:53'),
     array('name' => 1, 'distance' => 5.7, 'arrivetime' => '14:27', 'gotime' => '14:54'),
     array('name' => 1, 'distance' => 2.9, 'arrivetime' => '15:30', 'gotime' => '15:58'),
     array('name' => 2, 'distance' => 5.9, 'arrivetime' => '09:23', 'gotime' => '09:51'),
     array('name' => 2, 'distance' => 11.8, 'arrivetime' => '10:54', 'gotime' => '11:09'),
     array('name' => 3, 'distance' => 5, 'arrivetime' => '9:30', 'gotime' => '10:10'),
     array('name' => 3, 'distance' => 10, 'arrivetime' => '10:30', 'gotime' => '10:50'),
    );$last = array();
    foreach($ar as $row) {
      if($last) { //不是第一次进入
        $row['xingshi'] = (strtotime($row['arrivetime'])-strtotime($last['gotime']))/60;
        if($row['name'] == $last['name']) { //还是同一组
          $distance += $row['distance'];
          $xingshi += $row['xingshi'];
        }else {
          $row['xingshi'] = 0;
          echo "合计\t" . $distance . "\t\t\t" . $xingshi . 'min' . PHP_EOL;
          $distance = $row['distance'];
          $xingshi = 0;
        }
      }else {
        $distance = $row['distance'];
        $xingshi = 0;
      }
      $last = $row;
      echo join("\t", $row) . PHP_EOL;
    }
    echo "合计\t" . $distance . "\t\t\t" . $xingshi . 'min' . PHP_EOL; //输出最后一组的合计
    1 5.4 13:25 13:53
    1 5.7 14:27 14:54 34
    1 2.9 15:30 15:58 36
    合计 14 70min
    2 5.9 09:23 09:51 0
    2 11.8 10:54 11:09 63
    合计 17.7 63min
    3 5 9:30 10:10 0
    3 10 10:30 10:50 20
    合计 15 20min
      

  2.   

    非常感谢,已经按你的编码改变完成。
    而且给出的代码,也非常明了,容易理解修改后的代码<?php
    $sql="select * from record where officecode='$officecode' and searchtime like '%$riqi%' order by name limit $offset,$Page_size" ;
    $result=mysql_query($sql,$link);
    $last=array();
    while($row=mysql_fetch_array($result)){
    if($last){
      $row['xingshi'] = (strtotime($row['arrivetime'])-strtotime($last['gotime']))/60;
        if($row['name'] == $last['name']) { //还是同一组
          $distance += $row['distance']; //计算合计距离
          $xingshi += $row['xingshi']; //计算行驶时间
        }
    else { 
         //当组别变化时,行驶时间为0
          $row['xingshi'] = 0;
      ?>
            <td colspan="4"  bgcolor="#E0EEE">合计</td>
          <td><div align="center"> 
    <?php echo $distance."km"; ?> 
    </div></td>
    <td><?php echo $xingshi."min"; ?></td>
      <?php
         //合计完成后,重置行驶距离和行驶时间
          $distance = $row['distance'];
          $xingshi = 0;
        }
    }
    else {
        //每个name第一次进入时的行驶距离和时间
        $distance = $row['distance'];
        $xingshi = 0;
      }
    $last=$row; 
    ?>没有写出来的部分,退出while循环后 
    输出html和PHP的合计部分代码
    输出行驶时间 将echo $xingshi改为echo $row['xingshi']
      

  3.   


    补充下,昨天未说明的
    因为行驶时间的计算,输出变为echo $row['xingshi']
    所以现在计算时间的时候也要做出相对应的调整<?php
       //原来的代码
    echo $row['distance']/($xingshi/60);
      //现在的代码
      if($row['xingshi']!=0){
    echo $row['distance']/($row['xingshi']/60);
    }
    else{
    echo "0";
    }
    ?>