I have a simple set up in the database such as per below:
|--------------|------------------|--------------|------------|
| Image | Start Month | End Month | Active |
|--------------|------------------|--------------|------------|
| Image1.jpg | 10 | 3 | 1 | - Show October this year to March next year, every year.
| Image2.jpg | 3 | 10 | 1 | - Show March to October, every year.
| Image3.jpg | 7 | 5 | 1 | - Show July this year to May next year; every year.
| Image4.jpg | 0 | NULL | | - Show this image year round.
|--------------|------------------|--------------|------------|
The idea is to show images based on the month. Every year it's the same so a year is not required. Now the logic of how I am doing this is messing with my mind.
This month it's November (11). $month = 11;
The query I currently have is
WHERE `start_month` <= $month AND `end_month` >= $month OR `start_month`= 0 ORDER BY RAND()
but that unfortunately only works mid year and doesn't compensate for the images that wrap around into the new year.
What logic do I need to select the images based on the current month $month
between the start_month
and end_month
making it work for those images that cycle through the new year change.
Images with a 0
start month are to be displayed year round.