我想在我的数据库中得到这个列的总和并在主页中显示出来。这是屏幕截图
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);
最佳答案
如果此列time在mysql中是数据类型“time”,那么您的查询将是
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `time_duration` ) ) ) AS timeSum FROM hsncs_tbl;
关于php - 如何从PHP中的数据库中获取时间总和?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22526524/