I need to somehow look though every date between these dates and check each one and cross reference each date’s date(“w”) with a field in my database, if it matches then I print a record.
The idea is I have a month range from the $the_start to $the_end and I am trying to get a print out of say, each thursday. It’s for reocurring events in a calendar.
That doesn’t work for what I need. It doesn’t show me all the ‘thursdays’ within that range so I can match them up to the reocurring ‘thursday’ database record.
To explain further:
I have a table that stores the event name and the weekly reocurring day (date(“w”)) I then need to loop though the date range and each day that matches my reocurring field to then echo out the event name.
So your saying with MySQL I can select 1 record from a table, and it will generate 4 records for my script? e.g. I select the 1 record that has a reocurring day of thursday then it generates the 4 thursdays in my date range even though these records don’t exist?
To do to make it more clear to the others what you want to achieve, I guess what you need to do is give some example data from your database, and how you want that data to display.
Like:
table data:
Thursday Soccer game
Date range: 14 december 2010 - 24 december 2010
Result:
14
15
16 Soccer game
17
18
19
20
21
22
23 Soccer game
24
SELECT `fields` FROM `table`
WHERE date BETWEEN $start AND $end AND DATE_FORMAT(date, '%w') = $day_of_week
This assumes your events are only date (not datetime) resolution. You may need to adjust if the time of day matters.
Instead of BETWEEN you’d probably need to compare < the start of the next day, to ensure events up to midnight are included.