21,886
社区成员
发帖
与我相关
我的任务
分享
//主要部分代码
$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)){
while($row=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#E0EEE0" height="25px"><div align="center">
<?php echo $row['0']?>
</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></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['buildname']?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['distance']?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php
echo $xingshi=(strtotime($row['arrivetime'])-strtotime($row['gotime']))/60; // 主要是这部分的计算,现在的这个有问题
?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $dotime=(strtotime($row['gotime'])-strtotime($row['arrivetime']))/60 ; ?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['distance']/($dotime/60); ?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['arrivetime']?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['gotime']?>
</div></td>
</tr>
$ar = array(
array('id' => 1, 'name' => 'aa', 'len' => 1, 'f1' => 1, 'f2' => 2),
array('id' => 2, 'name' => 'aa', 'len' => 1, 'f1' => 3, 'f2' => 4),
array('id' => 3, 'name' => 'aa', 'len' => 1, 'f1' => 5, 'f2' => 6),
array('id' => 4, 'name' => 'bb', 'len' => 1, 'f1' => 2, 'f2' => 3),
array('id' => 5, 'name' => 'bb', 'len' => 1, 'f1' => 4, 'f2' => 5),
array('id' => 6, 'name' => 'bb', 'len' => 1, 'f1' => 6, 'f2' => 7),
array('id' => 7, 'name' => 'bb', 'len' => 1, 'f1' => 8, 'f2' => 9),
);
$last = array();
$sub = 0;
$subtotal = 0;
$total = 0;
foreach($ar as $v) {
if($last && $v['name'] == $last['name']) {
$sub = $v['f2'] - $last['f1'];
$total += $v['len'];
$subtotal += $sub;
}else {
if($last) printf('%s %s %s %s %s %s<br />', '合计', $v['name'], $total, $v['f1'], $v['f2'], $subtotal);
$total = $v['len'];
$subtotal = 0;
}
$last = $v;
printf('%s %s %s %s %s %s<br />', $v['id'], $v['name'], $v['len'], $v['f1'], $v['f2'], $sub);
}
printf('%s %s %s %s %s %s<br />', '合计', $v['name'], $total, $v['f1'], $v['f2'], $subtotal);
1 aa 1 1 2 0$last = array();
while($row=mysql_fetch_array($result)) {
if($last && $row['name'] == $last['name']) {
//在这里计算
//在这里累加
}
$last = $row;
只要你理解了就会自己写$last = array(); //用于缓存上一记录
$sum = 0;
while($row=mysql_fetch_array($result)){
if($last) {//不是第一次进入
if($row['name']==$last['name']) {//还是同一个人
$xingshi = (strtotime($row['arrivetime'])-strtotime($last['gotime']))/60;
$sum += $row['distance']; //对 $row['distance'] 求和;
} else {
//换人了
$xingshi = 0;
//输出合计行
$sum = 0;
}
}
$last = $row; //缓存当前记录供后边使用
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>确认页面</title>
</head>
<body>
<?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);
$last=array();
while($row=mysql_fetch_array($result)){
/*if($last && $row['name']==$last['name']){
echo $xingshi=(strtotime($row['arrivetime'])-strtotime($last['gotime']))/60;
$j1=$row['distance'];
$sum=$sum+$j1;
}
else{
}
$last=$row;
*/
?>
<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></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['buildname']?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['distance']?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php
if($last && $row['name']==$last['name']){
echo $xingshi=(strtotime($row['arrivetime'])-strtotime($last['gotime']))/60;
//echo $xingshi;
}
$last=$row;
?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $dotime=(strtotime($row['gotime'])-strtotime($row['arrivetime']))/60 ; ?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['distance']/($dotime/60); ?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['arrivetime']?>
</div></td>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $row['gotime']?>
</div></td>
</tr>
<?php
$j1=$row['distance'];
$sum=$sum+$j1;
?>
<?php
}
?>
<td bgcolor="#E0EEE"><div align="center">
<?php echo $sum."km"; ?>
</div></td>
<?php
$page_len=($page_len%2)?$page_len:$pagelen+1;//页码个数
$pageoffset = ($page_len-1)/2; //页码个数左右偏移量
$key='<div class="page">';
$key.="<span>$page/$pages</span>"; //第几页,共几页
if($page!=1){
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=1\">第一页</a>";//第一页
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">上一页</a>"; //上一页
}
else{
$key.="第一页";//第一页
$key.="上一页";//上一页
}
if($pages>$page_len){
//如果当前页小于等于左偏移
if($page<=$pageoffset){
$init=1;
$max_p = $page_len;
}
else{
//如果当前页大于左偏移
//如果当前页码右偏移超出最大分页数
if($page+$pageoffset>=$pages+1){
$init = $pages-$page_len+1;
}
else{
//左右偏移都存在时的计算
$init = $page-$pageoffset;
$max_p =$page+$pageoffset;
}
}
}
for($i=$init;$i<=$max_p;$i++){
if($i==$page){
$key.='<span>'.$i.'</span>';
}
else{
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=".$i."\">".$i."</a>";
}
}
if($page!=$pages){
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">下一页</a>"; //下一页
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page={$pages}\">最后一页</a>"; //最后一页
}
else{
$key.="下一页"; //下一页
$key.="最后一页";//最后一页
}
$key.='</div>';
//echo $sql;
?>
<tr>
<td colspan="13" bgcolor="#E0EEE0"><div align="center"><?php echo $key ?></div></td>
</tr>
</table>
</div>
<!--
<div align="center"><?php echo $key ?> 第<input type="text" name="page" style="width:25px;" />页
<input type="button" value="go" onClick="tijiao()">
</div>
-->
<br><br><br><br><br><br>
</table>
<div align="center">
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<input type="button" value="返回输入页面" onClick="location.href='write.php'" />
</div>
</form>
</body>
</html>
<?php echo $dotime=(strtotime($row['gotime'])-strtotime($row['arrivetime']))/60 ; ?>