i have a senario where user reg for seminar and books a hall, during reg he enters start time and end time for seminar ,start and end time are stored in data base. when a new user reg for seminar hall with existing booked time in data base
it should alert to user selected time not available.

I need a logic any help wou1d be appreciated.

 if($StartTime>=$StartTime_DB || $StartTime<=$StartTime_DB && $StartTime<=$EndTime_DB)
        {    
            echo "select some other time";
            exit();
        }

it is not working for all values

Member Avatar for diafol

OK, depending on the bookable resources and the time/date format used:

I will assume the easiest, which IMO:

TABLES
resources
[id, name, description, (etc)]
users
[id, username, pw, (etc)]
bookings
[id, user_id, resource_id, from_time,to_time, description,(etc)]

Ensure that time formats are unix-based integer timestamps. DO NOT use separate date & time.

$check_start_d = ...; //post or get start date
$check_end_d = ...; //post or get end date - maybe you only allow single day bookings - if so, this is not relevant.
$check_start_t = ...; //post or get start time
$check_end_t = ...; //post or get end time

/*
TURN date and time into unix integer timestamp - can be done with mysql alone, but much better with php as you can validate - I'll leave validation to you and any re-formatting of dates to unix format (e.g. dd/mm/yyyy to yyyy-mm-dd). We'll call the transformed variables: $start, $end.
*/

$res = ...; //resource id from post or get (e.g. room id)
$filter = ...; // ok this is another bit you'll can do yourself - see below

$check= mysql_query("SELECT description FROM bookings WHERE resource_id = '$res' AND $filter");
if(mysql_num_rows($check) > 0){
   //clash - no can do
}else{
   //ok to book
}

For the $filter variable which contains the stuff in which you're interested, you need to test for the following scenarios, where, if either is true, there would be a clash. Hint - not all of the scenarios have to be tested.

OK, depending on the bookable resources and the time/date format used:

I will assume the easiest, which IMO:

TABLES
resources
[id, name, description, (etc)]
users
[id, username, pw, (etc)]
bookings
[id, user_id, resource_id, from_time,to_time, description,(etc)]

Ensure that time formats are unix-based integer timestamps. DO NOT use separate date & time.

$check_start_d = ...; //post or get start date
$check_end_d = ...; //post or get end date - maybe you only allow single day bookings - if so, this is not relevant.
$check_start_t = ...; //post or get start time
$check_end_t = ...; //post or get end time

/*
TURN date and time into unix integer timestamp - can be done with mysql alone, but much better with php as you can validate - I'll leave validation to you and any re-formatting of dates to unix format (e.g. dd/mm/yyyy to yyyy-mm-dd). We'll call the transformed variables: $start, $end.
*/

$res = ...; //resource id from post or get (e.g. room id)
$filter = ...; // ok this is another bit you'll can do yourself - see below

$check= mysql_query("SELECT description FROM bookings WHERE resource_id = '$res' AND $filter");
if(mysql_num_rows($check) > 0){
   //clash - no can do
}else{
   //ok to book
}

For the $filter variable which contains the stuff in which you're interested, you need to test for the following scenarios, where, if either is true, there would be a clash. Hint - not all of the scenarios have to be tested.

I thank u for the help. It helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.