【问题标题】:How to display the sum of time from database using php?如何使用php显示数据库中的时间总和?
【发布时间】:2014-03-19 03:18:09
【问题描述】:

我用它作为我的计时器并将这些数据保存到数据库中

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

我想在我的系统中使用它,我需要立即完成它。请帮我完成我的项目。感谢您的大力帮助。谢谢你:)

【问题讨论】:

  • 当我说“项目”时——这并不意味着我还在上学。呃?
  • 对不起。这是我提交数据的方式。请再次检查代码。谢谢

标签: javascript php timer


【解决方案1】:

您需要使用 SQL ..SQL 示例是:

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

可能对你有帮助

【讨论】:

  • 接下来在哪里?
猜你喜欢
  • 2011-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多