我在此代码中加了限制,但如何计算此页面中的 totalmin ?
这是我的代码
<?php
$id = $_GET['id'];
$sql = "SELECT * FROM time WHERE id = $id ORDER BY id DESC LIMIT 15";
$result = mysql_query($sql);
?>
<table border="0" style="width:50%">
<tr>
<th>Time in</th>
<th>Time Out</th>
</tr>
<?php
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td><center>".$row['totalmin']."</center></td>";
echo "</tr>";
}
</table>
mysql_close();
我想知道如何用PHP代码累计15行中的所有分钟
答案 0 :(得分:0)
如果element.style.backgroundImage = "url(localPath/to/image.gif)";
小于$totalmin
,则需要将$row['totalmin']
存储到while循环中并使用新值进行更新。
使用类似的东西:
$totalmin
答案 1 :(得分:0)
在循环结果时总结分钟数:
$sum = 0;
while($row = mysql_fetch_array($result)){
$sum += floatval($row['totalmin']); //or intval()
echo "<tr>";
echo "<td><center>".$row['totalmin']."</center></td>";
echo "</tr>";
}
echo $sum;
确保关闭while循环
答案 2 :(得分:0)
$id = $_GET['id'];
$sql = "SELECT * FROM time WHERE id = $id ORDER BY id DESC LIMIT 15";
$result = mysql_query($sql);
$sum = 0;
$num = 0;
?>
<table border="0" style="width:50%">
<tr>
<th>Time in</th>
<th>Time Out</th>
</tr>
<?php
while($row = mysql_fetch_array($result)){
$num++;
$sum += $row['totalmin'];
echo "<tr>";
echo "<td><center>".$row['totalmin']."</center></td>";
echo "</tr>";
if($num == 15){
echo "<tr>";
echo "<td><center>".$sum."</center></td>";
echo "</tr>";
}
}
?>
</table>
<?php
mysql_close();