如何从PHP中获取数据库的时间总和?

时间:2014-03-20 07:44:30

标签: php mysql

我想在我的数据库中获取此列的总和并将其显示在主页中。这是屏幕截图

http://bit.ly/1fJ7Cey

我使用此代码在我的数据库中保存数据

$timeanddate=$_POST['timeanddate'];
$time=$_POST['tst'];
$name=$_POST['name'];   
$number=$_POST['number'];
$disposition=$_POST['disposition'];
$remarks=$_POST['remarks'];
$times=$_POST['timetoday'];
$dates=$_POST['datetoday'];

if(isset($_POST['submit']))
{
session_start();
$con=mysqli_connect("localhost","root","","hsncs_db");

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="INSERT INTO hsncs_tbl (id, name, number, call_disposition, remarks, time, date, time_duration, hsncs_user)
VALUES
('', '$_POST[name]', '$_POST[number]', '$_POST[disposition]', '$_POST[remarks]', '$_POST[timetoday]', '$_POST[datetoday]', '$_POST[tst]', '$_SESSION[fname]')";

if (!mysqli_query($con,$sql))
{
  die('Error: ' . mysqli_error($con));
}

mysqli_close($con);

1 个答案:

答案 0 :(得分:1)

如果此列时间在mysql中的数据类型为“时间”,那么您的查询将是

SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `time_duration` ) ) ) AS timeSum FROM hsncs_tbl;