日期:2014-05-17  浏览次数:20471 次

关于$row中的计算



员工编号、姓名、no、物件名称、行驶距离、到达时间、出发时间可通过数据库 $row['']直接获取
  行驶时间、行驶速度、作业时间需要进行计算获取
  作业时间我是这样获取的<?php echo $dotime=(strtotime($row['gotime'])-strtotime($row['arrivetime']))/60 ; ?> 
  行驶速度的获取 <?php echo $row['distance']/($dotime/60); ?> 
   
  问题1:这个行驶时间用excel来描述的话例如zhangsan的no=2的行 为 I3-J2 以此类推I4-J3,I5-J4,。。这个能不能进行处理,有没有什么$row+1错行计算的方法?
  问题2:要求是按姓名分组 这里是不是用group by比较好?如果用order by可以吗?
  问题3:每个人之后,还要有合计,例如需要计算行驶距离的和、行驶时间的和、作业时间的和,这部分要如何处理?
  问题4:整个工作内容是不是用PHPEXCEL更容易处理一些?
   
  谢谢

php目前代码情况如下:

PHP code
<?php

include('conn.php');
$officename=$_POST['officename'];
$date=$_POST['riqi'];
$sql1="select * from record where officename='$officename' and searchtime like '%$riqi%' order by name";
$result1=mysql_query($sql1);
if(mysql_num_rows($result1)!=0){
    $row=mysql_fetch_assoc($result1) ;
    $officecode=$row['officecode'];
    
}
else{
    echo "没有这样的记录,正在返回确认页面";
    echo "<meta http-equiv='refresh' content='2;url=confirm.php'>";
}

?>

日期:<?php echo $date; ?>——待机点NO:<?php echo $officecode; ?>——待机点名称:<?php echo $officename; ?>

<form name="form3">
<div align="center">
<table width="1230" height="103" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<!-- 将要列出的内容-->
<th width="50" height="38" bgcolor="#E3E3E3" scope="col">员工编号</th> 
<th width="90" bgcolor="#E3E3E3" scope="col">姓名</th> 
<th width="70" bgcolor="#E3E3E3" scope="col">NO.</th>
<th width="40" bgcolor="#E3E3E3" scope="col">物件名称</th>
<th width="80" bgcolor="#E3E3E3" scope="col">行驶距离</th>
<th width="80" bgcolor="#E3E3E3" scope="col">行驶时间</th>
<th width="80" bgcolor="#E3E3E3" scope="col">作业时间</th>
<th width="100" bgcolor="#E3E3E3" scope="col">行驶速度</th>
<th width="60" bgcolor="#E3E3E3" scope="col">到达时间</th>
<th width="60" bgcolor="#E3E3E3" scope="col">出发时间</th>
</tr> 
<?php
$link=mysql_connect('localhost','root','mysql');  //数据库用户名及数据库密码
mysql_select_db('berecord');  //数据库名称
mysql_query('set names utf8');

$Page_size=10;  //设置每页显示个数

$result=mysql_query("select * from record where officecode='$officecode' and searchtime like '%$riqi%' order by name");    //record为表名
$count = mysql_num_rows($result);
$page_count = ceil($count/$Page_size);

$init = 1;
$page_len = 7;
$max_p=$page_count;
$pages=$page_count;

//判断当前页码
if(empty($_GET['page'])||$_GET['page']<0){
$page=1;
}
else{
$page=$_GET['page'];
}

$offset=$Page_size*($page-1);
$sql="select * from record where officecode='$officecode' and searchtime like '%$riqi%' order by name limit $offset,$Page_size" ;
$result=mysql_query($sql,$link);
//$row=mysql_fetch_array($result);
while($row=mysql_fetch_array($result)){
?>
<tr> 
<td bgcolor="#E0EEE0" height="25px"><div align="center"> 
<?php echo $row['mencode'] ?>
</div></td>
<td bgcolor="#E0EEE"><div align="center"> 
<?php echo $row['name']?> 
</div></td>
<td bgcolor="#E0EEE"><div align="center"> 
<?php echo $row['record']?> 
</div></