UPDATE
I edited my code, so now the time is checked correctly:
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);
}
}
}
So now: how do I check if $ok contains one or more 0
's (don't book the room) or all 1
's (book the room).
$roomstate = array(state => $ok)
results in more than one array:
Array ( [state] => 0 ) Array ( [state] => 1 ) Array ( [state] => 1 )
I'm doing something wrong, because I think it should be possible to get all the different $ok
's in one array and then
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 1259 So 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?