I would store with 2 fields.
data
, field date
same (or int
counting number of days of a standard date).
periodo
field int
1 byte only, or enum
being:
1
= morning
2
= late
3
= both periods
Thus simplifies the problem.
Checking if the date is free.
To test date availability, just do this select
:
SELECT periodo WHERE data=$data AND ( periodo=$periodo OR periodo=3 OR $periodo=3 );
periodo=$periodo
means conflict, if you asked for it tomorrow and it’s morning, or if you asked for it late and it’s late
periodo=3
means conflict, because if you already have one occupying the whole day, you cannot schedule anything else on that date.
$periodo=3
means conflict because if you are trying to schedule all day, any existing scheduling prevents scheduling.
If the query above do not return any record, you can make a new schedule on the date $data
for the period $periodo
.
If, on the other hand, records return, it is not possible to put the new schedule, because it will have a conflict.
Not the structure of that part
( periodo=$periodo OR periodo=3 OR $periodo=3 );
– Tiago
They are the 3 tests that I explained above. period=$period eliminates late with late, and morning with morning. period=3 eliminates any scheduling if the whole day is busy. $period=3 eliminates scheduling for the whole day if anything else already exists that day.
– Bacco