I have a calendar where there are different background colours applied to each cell dependant on different variables using PHP. I'm using if statements to alter the style set to the TD based on whether the day is todays date, if a shift has been booked that day or if a holiday is booked that day.
This has worked, but then I realised that if a holiday was booked on a day that is a shift regardless of whether or not its a holiday it still gets coloured as a shift. I understand that this is because of the order of the IF statements. So I was going to ask whether there was any way around this...
But then I realised as I'm working with a system with different users not just one person, if it was one person this wouldn't matter because they can't book the same day as a shift AND holiday.
However... each user can see if a day is booked as a shift or holiday by the colour of it (without showing more detail, such as the user who has that day booked) that I would need to assign a different colour to a day that has been booked for both a shift or a holiday.
So after realising all this (sorry if its useless backstory) my question is now (at least I think it is..!) how do I create a MySQL statement that will select from the table where the date booked has entries as a shift and a holiday.
My database is designed with five columns: id, surname, stafflevel, datebooked and typebooked. my current code for the way it works now is:
$ifShift ="SELECT * FROM schedule WHERE dateBooked = '".$dateToCompare."' AND typeBooked = 'shift'";
$tdShift = mysql_num_rows(mysql_query($ifShift));
$ifHoliday ="SELECT * FROM schedule WHERE dateBooked = '".$dateToCompare."' AND typeBooked = 'holiday'";
$tdHoliday = mysql_num_rows(mysql_query($ifHoliday));
if ($tdShift) {
echo "class='shift'";
} elseif($tdHoliday) {
echo "class='holiday'";
}
I tried using
select * from schedule where dateBooked = '26/12/2014' AND (typeBooked = 'shift' AND 'holiday');
in terminal to test this with my table and got a message "Empty set, 1 warning"... so how do I go about this... if it's even possible?
But also wont I still have my original problem of the order of the if statements?
Thanks guys!