2014-03-19 28 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

相關問題