title: PHP/MySQL: Model repeating events in a database but query for date ranges
body: <p>I'm working on a (what I was intending to be) simple PHP/MySQL app. As part of it I'd like to be able to model repeating events, however I need to be able to query all the events that happened between two dates (including repeated events). The events only have a date, the time of day doesn't matter.</p>
  
  <p>I've been researching this and have looked in to various approaches including  <a href="https://stackoverflow.com/questions/5183630/calendar-recurring-repeating-events-best-storage-method">Calendar Recurring/Repeating Events - Best Storage Method</a> and <a href="https://stackoverflow.com/questions/10545869/repeating-calendar-events-and-some-final-maths">Repeating calendar events and some final maths</a>.</p>
  
  <p>However, any example of a database schema supporting this that I find online, only seems to support querying for events that happened on a certain day. There is no support for events that happened between a range of dates.</p>
  
  <p>As an abstract example</p>
  
  <p>Events table (with some sort of repeat representation):</p>
  
  <pre><code>Event   | Start Date   |   Repeats
  -------------------------------------
  Meeting | 10/Dec/2012  |   Every 7 days
  Lunch   | 10/Dec/2012  |   Every 1 days
  </code></pre>
  
  <p><strong>Target</strong> result of abstract query <code>SELECT Events BETWEEN 09/Dec/2012 AND 20/Dec/2012</code></p>
  
  <pre><code>Event   |  Date        |   Repeats
  -------------------------------------
  Meeting | 10/Dec/2012  |   Every 7 days
  Meeting | 17/Dec/2012  |   Every 7 days
  Lunch   | 10/Dec/2012  |   Every 1 days
  Lunch   | 11/Dec/2012  |   Every 1 days
  Lunch   | 12/Dec/2012  |   Every 1 days
  Lunch   | 13/Dec/2012  |   Every 1 days
  etc...
  Lunch   | 20/Dec/2012  |   Every 1 days
  </code></pre>
  
  <p>Is there a database schema that will support these kind of queries? How would I go around making a query on that schema for any event (including repeating events) that happened between two days?</p>
  
  <p>Or perhaps a design pattern that is used for repeating events?</p>