2014-03-19 30 views
2

我用这个作为我的计时器和这个数据保存到数据库如何显示使用php数据库的时间总和?

<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> 

我要显示所有从数据库中的计时器的总和。我不知道如何编码。

<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> 

我使用此代码将我的数据提交给数据库。

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); 

我想使用它到我的系统,我需要马上完成它。请帮我完成我的项目。我感谢你的大力帮助。谢谢:)

+2

当我说“工程” - 这并不意味着我仍然在学校。咄? – Chad

+2

对不起。以下是我提交数据的方式。请再次检查代码。谢谢 – Chad

回答

0

你需要使用SQL ..SQL样本:

SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(`total_time`))) FROM `table` WHERE . . 

可能是它帮助你

+2

下一步在哪里? – Chad

相关问题