I'm accessing a database created by another web company to retrieve event information for my current client. My client enters info for events and notes whether the date is recurring or not. I'm trying to display all the recurring dates. So far I have been able to get everything to display, regular dates as well as recurring.
The tables are laid out as follows:
- Events
- Events_Recurring
Here is part of the Events table BIGGER PICTURE

This is what the Events_Recurring table looks like

When the client checks it as recurring, the events_recurring table creates a row with the Event ID and other information like what day of the week or month the event is recurring on.
I'm just not sure how to display multiples of that certain ID that is recurring. I have a start date, and end date I can access, as well as what day of the week it is recurring on.
So for example: If this event reoccured every thursday. and I knew it started on Jan 1st and ended Jan 31st, can I run through that and spit out 4 different events all with the date of every Thursday in January?
Here is the full code I am working with, it's a little messy while trying to figure this out. I'm checking for the recurrence towards the bottom
// Access external database
$events_db = new wpdb(TOP SECRET CREDENTIALS HERE);
$events_db->show_errors();
if ($events_db) :
// Query Events Database
$events = $events_db->get_results(
"
SELECT ID, RequestDateStart, RequestDateEnd, Ministry, RequestTimeStart, EventName, CoordinatorName, EventDescription, Location
FROM gc_events
WHERE PrivateEvent = 0
AND Ministry = 15
AND date(RequestDateStart)>=date(NOW())
ORDER BY RequestDateStart
"
);
// Create the event data that will be displayed
foreach ($events as $event) :
// Store Event ID in a variable
$masterID = $event->ID;
echo '<div class="col-12">';
echo '<strong>ID:</strong> ' . $event->ID . '<br /><strong>Event Name:</strong> ' . $event->EventName . '<br /><strong>Leader:</strong> ' . $event->CoordinatorName . '<br /><strong>Date:</strong> ' . date('l, F j',strtotime($event->RequestDateStart)) . '<br /><strong>Start Time:</strong> ' . date('g:i a',strtotime($event->RequestTimeStart));
// CHECK IF RECURRING
$recurring_events = $events_db->get_results(
"
SELECT gc_event_id, period, day
FROM gc_event_recurring
WHERE gc_event_id = '$masterID'
"
);
foreach ($recurring_events as $recurring_event) :
if ($recurring_event->period === 'week') {
echo '<div class="col-12"><strong>↑ WEEKLY</strong><br />';
echo $recurring_event->day;
echo '</div>';
}
endforeach;
echo '</div>';
endforeach;
endif;
The result I am getting right now (with recurring events) is
Event: Weekly Prayer
Date: Feb 1, 2013
The result I would like is
Event: Weekly Prayer
Date: Feb 1, 2013
Event: Weekly Prayer
Date: Feb 8, 2013
Event: Weekly Prayer
Date: Feb 15, 2013
Event: Weekly Prayer
Date: Feb 22, 2013
This would be if the start date was Feb 1st and end date was Feb 28th.
($recurring_event->period === 'week')do not use===use==