gpt4 book ai didi

php - 将表单中的日期/时间与数据库中的日期/时间进行比较

转载 作者:行者123 更新时间:2023-11-30 00:45:29 24 4
gpt4 key购买 nike

更新

我编辑了代码,所以现在时间检查正确:

while($row = mysqli_fetch_array($result)){
$rid = $row['roomid'];
$begin = $row['start'];
$bval = strtotime($begin);
$einde = $row['end'];
$eval = strtotime($einde);

$staco = strtotime($start); //starttime posted from form
$endco = strtotime($end); //stoptime posted from form


$abegin = array(sta => $bval);
$aeinde = array(sto => $eval);
// print_r($abegin);
// print_r($aeinde);
foreach($aeinde as $sto) {
if($staco <= $sto) {$checksto = 1;}
else {$checksto = 0;}
}

foreach($abegin as $sta) {
if($endco <= $sta) {$checksta = 1;}
else {$checksta = 0;}
}


if($checksta == $checksto) {$ok = 1;} else {$ok = 0;}

print_r($ok);

}
}
}

现在:我如何检查 $ok 是否包含一个或多个 0(不预订房间)或所有 1(预订房间)房间)。

$roomstate = array(state => $ok) 结果产生多个数组:

Array ( [state] => 0 ) Array ( [state] => 1 ) Array ( [state] => 1 )

我做错了一件事,因为我认为应该可以在一个数组中获取所有不同的$ok,然后

if(in_array(0,$roomstate)) { echo "Do not book";} else {$bookitsql = "INSERT INTO reservations ...";}
UPDATE: There is a flaw in my original logic to check availabilty with the rooms that needs to be solved first: now the rooms are not checked correct, so it is impossible to answer this question since the correct data is not displayed. My apologies.For a system that books rooms I need to check with a new booking if the room is already is booked at the moment. The booking works with a form, and then it compares the results from the form with the content in the database for that room on that date.    while($row = mysqli_fetch_array($result)){      $rid = $row['roomid'];      $begin = $row['start'];      $bval = strtotime($begin);      $staco = strtotime($start);      $einde = $row['end'];      $eval = strtotime($einde);      $endco = strtotime($end);      $abegin = array(sta => $bval);      $aeinde = array(sto => $eval);        foreach($abegin as $sta) {        if($staco  $checksta,checkstop => $checksto);          print_r($meh);    }BetterQuestion:Now I get `$staco` and `$endco`, which are the start and stoptime from the form.I also get `$sta` and `$sto`, which are multiple start and stoptimes from the database.Example: existing reservations:        sta     sto    1:  0800    0959    2:  1130    1259So now when I get `$staco = 1000` and `$endco = 1114` it doesn't check right.It only works if the new reservation is later than all the other reservations in the database. How can I solve this?

最佳答案

你的目标伪代码表明你希望它全部为0。$meh是一个数组。因此,您现在要做的就是在 $meh 上使用 foreach,然后在 1 出现时将其标记为已占用。如果这种情况没有发生,您可以假设 $meh 是免费的,并进行预订。

$roomState = 0;
foreach($meh as $mehValue){
if($mehValue == 1){
$roomState = 1;
}
}
if($roomState == 1){
print_r("room is occupied");
} else {
//insert stuff
}

关于php - 将表单中的日期/时间与数据库中的日期/时间进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21407092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com