在php中添加爆炸时间

tcomlyy6  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(279)

我有一个表服务字段是proc\u id、proc\u no、proc\u services、proc\u time和proc\u price。我要添加服务的所有过程时间(proc\u 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;
2w3kk1z5

2w3kk1z51#

您需要将每个过程的所有时间相加,然后将其添加到开始时间,这样就可以循环每个过程(我假设 $_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;

相关问题