在PHP中添加爆炸时间

时间:2019-01-05 16:18:34

标签: php mysql datetime

我有一个表服务,这些字段是Proc_ID,Proc_No,Proc_Services,Proc_time和Proc_Price。我要添加服务的所有过程时间(Proc_Time)。

这是代码

If
00:15:00

00:30:00

答案是00:45:00 ..但是我的代码得到了错误的答案。如果开始时间为每小时9:00,服务1的时间为00:15:00,服务2的时间为00:30:00,则预订结束时间为9:45。

$dt = $_POST['restime'];
$p1 = $_POST['dermaproc'];

$tmp = "";

foreach ($p1 as $key) {
    $tmp .= $key;
}

$today = strtotime("TODAY");

 $sql3 = "SELECT * FROM services WHERE Proc_ID = '$tmp' ";
 $res3 = $conx->query($sql3);
 $row3 = $res3->fetch_assoc();

      $explode = explode(",", $tmp); 
      foreach ($explode as $key1) {

 $sql4 = "SELECT Proc_Time FROM services WHERE Proc_ID = '$key1'";

      $res4 = $conx->query($sql4);
      $row4 = $res4->fetch_assoc();
      $pt = $row4['Proc_Time'];
      $m_time1 = strtotime($dt) - $today;
      $m_time2 = strtotime($pt) - $today;
      $m_total = $m_time1 + $m_time2 + $today;
      $etime = date('h:i:s', $m_total);

      echo    $etime;

1 个答案:

答案 0 :(得分:0)

您需要将每个过程的所有时间加起来,然后将其添加到开始时间,因此这会循环每个过程(我假设$_POST['dermaproc']包含过程列表),只需将循环中每个过程的时间相加即可。循环之后,它将总时间添加到约会开始时间。

$dt = $_POST['restime'];
$p1 = $_POST['dermaproc'];
$today = strtotime("TODAY");

$m_total = 0;
foreach ($p1 as $key1) {
    $sql4 = "SELECT Proc_Time FROM services WHERE Proc_ID = '$key1'";
    $res4 = $conx->query($sql4);
    $row4 = $res4->fetch_assoc();
    $m_total += strtotime($row4['Proc_Time']) - $today;
}
$etime = date('H:i:s', $m_total+strtotime($dt));

echo     $etime;