如何使用php显示数据库的时间总和? [英] How to display the sum of time from database using php?
本文介绍了如何使用php显示数据库的时间总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将此作为我的计时器并将此数据保存到数据库
I use this as my timer and save this data to database
<input type="text" class="timer timer-count timer-box" id="tst" name="tst" value="0:0" readonly="readonly"/>
<br /><br />
<script>
/*<![CDATA[*/
var timer={
init:function(id){
this[id]={
obj:document.getElementById(id)
}
},
start:function(id){
var obj=this[id];
obj.srt=new Date();
clearTimeout(obj.to);
this.tick(id)
},
stop:function(id){
clearTimeout(this[id].to);
},
tick:function(id){
this.stop(id);
var obj=this[id],sec=(new Date()-obj.srt)/1000,min=Math.floor(sec/60),sec=sec%60;
obj.obj.value=min +':'+parseInt(sec>1?sec:'0'+sec);
obj.to=setTimeout(function(){ timer.tick(id); },1000);
}
}
timer.init('tst');
/*]]>*/
</script>
我想显示数据库中所有计时器的总和。我不知道如何编码。
I want to display the sum of all the timer from database. I don't know how to code it.
<table class="table table-bordered sans-pro-light">
<thead>
<tr>
<th class="text-center text-top">TOTAL TIME</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-center"><?php /* DISPLAY TOTAL SUM OF TIME HERE */ ?></td>
</tr>
</tbody>
</table>
我使用此代码将数据提交到数据库。
I use this code to submit my data to database.
if(isset($_POST['submit']))
{
session_start();
$con=mysqli_connect("localhost","root","","hsncs_db");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO hsncs_tbl (id, time_duration)
VALUES
('', '$_POST[tst]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
我想将它用于我的系统,我需要马上完成它。请帮我完成我的项目。我很感激你的帮助。谢谢:)
I wanted to use this to my system and I need to finish it right away. Please help me finish my project. I appreciate your big help. Thank you :)
推荐答案
你需要使用SQL ..SQL示例是:
you need to use SQL ..SQL sample is :
SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(`total_time`))) FROM `table` WHERE . .
可能会帮助你
这篇关于如何使用php显示数据库的时间总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文