This topic is locked

Check if specific Record exists in a Date Range

1/27/2012 3:45:45 PM
PHPRunner General questions
M
macskafogo author

Hi !
I want to prevent a user from booking a Room when someone else already added the same booking date range.

The table is "calendar" and the column names are "StartDateField" "Starttimefield" "endDatefield" "wndtimefield" and "category".
Thank you.

C
cgphp 1/27/2012

In the "Before record added" event enter this code:

$rs = CustomQuery("SELECT * FROM calendar WHERE

StartDateField >= '".$values['StartDateField']."' AND

endDatefield <= '". $values['endDatefield']."' AND

Starttimefield >= '".$values['Starttimefield']."' AND

endtimefield <= '".$values['endtimefield']."' AND

category = '".$values['category']."'");
$record = db_fetch_array($rs);
if($record)

{

$message = "The room is already booked";

return false;

}