Closed Thread Icon

Topic awaiting preservation: Recurring Events in MySQL/PHP Calendar (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26959" title="Pages that link to Topic awaiting preservation: Recurring Events in MySQL/PHP Calendar (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Recurring Events in MySQL/PHP Calendar <span class="small">(Page 1 of 1)</span>\

 
Kristo
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2004

posted posted 11-04-2005 04:05

I'm setting up a MySQL based calendar in PHP on a website. I've learned how to do simple things like adding/deleting/editing events, displaying with calc.php, etc.

I'd like to be able to add recurring events, but not sure how to code this. I'd like to choose events that are repeating in three ways:
1. Multiple days in a row (Monday-Wednesday)
2. Repeating on same day of each week (every Monday)
3. Repeating on same date of each month (5th of every month)

Right now when I create an event it is a single record in my calendar table. If anyone can point me in the right direction, either by giving me code examples or pointing me to good tutorials online, I'd appreciate it. Seems like every time I Google "php calendar" all I get are calendar scripts already pre-done & for sale. I really don't want a huge calendaring system already predone - I'd rather have a smaller, simpler one that fits right into what I'm doing without all of the extra stuff.

Thanks for your help!

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-04-2005 08:50

well, one approach is to store each calendar entry with a next and previous entry link - in the reoccuring row that is.
Then you simple create all the single entries for a reoccuring event, link them (or even give them a reoccuringId, that's the better approach).
Next time you modify it, delete all the single entries, store them a new.

so long,

->Tyberius Prime

Kristo
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2004

posted posted 11-05-2005 22:28

Okay, I think I've opted to insert individual entries for multi-day & recurring events. I'm not sure how to do this in MySQL/PHP, though. Can someone give me an example of how I can do this? What would the code look like for this:

Using an event entry form, I choose to have an event repeat every Sunday from STARTDATE to ENDDATE (let's say it is a total of 4 weeks for this example).

Thanks again for your help!

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 11-05-2005 23:08

Would be easier to help if you gave us the structure of your database - how you are storing the data will determine how you must enter and recall it.

Kristo
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2004

posted posted 11-05-2005 23:19

Okay - the whole thing is too complex. Here is the simple part - I can expand this to work with the whole thing:

Calendar Table:
parent_id
event_id
event_title
event_description
start_date
end_date
recurrance

The form gives the ability to choose between the following for 'recurrance':
Daily
Weekly (on same day of the week)
Monthly (on same date of each month)
Yearly (on same date)

What I need to know is how to insert multiple records into my database when I process the form. If someone chooses the start_date for Oct 1, the end_date as Nov 1, and the recurrance as daily, I want to insert individual records of that event for each day between those two dates.

The script will generate a unique parent_id based using different field values and auto-increment an event_id for each day. This way I can edit all the events according to the parent_id, or delete single dates that are exceptions in that date range (in case the event is cancelled on Oct 15, for example).

Does this help? Like I said, the actual system is a lot more complex than that, but this will give me the start I need.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 11-06-2005 00:08

what value will you store in the 'recurrence' field?

Basically you'll need to calculate the number of recurrences between the start and end, and figure out what the dates of the recurrences will be.

Then it's just a matter of running a loop to repeat the function that will insert the data, incrementing the date accordingly.

There are a lot of options for calculating the dates with PHP - http://us2.php.net/manual/en/function.date.php will give you a starting place.

In particular, strtotime and mktime should be of use.

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-06-2005 02:39

I'm actuly currently working on a calendar that does exactly what you want. It currently functions properly, but I do have bugs to squish and need to figure out some portability issues.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-06-2005 21:49

My first instinct on this is that you don't want to recurrance in the same table as the event entry. I'd abastract these out a bit.

Event Table
parent_id
event_id
event_title
event_description
event_type // Some id like daily weekly, monthly

Daily event table:
event_id
start_date
end_date

Day of week event table
event_id
start_date
end_date
day_of_week

Monthly Event Table
event_id
start_date
end_date
day_of_month


This would prevent you from trying to shoehorn all these event types into one field plus in regards to this type of app its good to abstract the event data from the calendering



.:[ Never resist a perfect moment ]:.

Kristo
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2004

posted posted 11-07-2005 16:50
quote:

DL-44 said:
what value will you store in the 'recurrence' field?



The 'type' of the event:
Daily
Weekly (on same day of the week)
Monthly (on same date of each month)
Yearly (on same date)

I'd use this field to figure out the interval of dates to insert.

quote:

zavaboy said:


I'm actuly currently working on a calendar that does exactly
what you want. It currently functions properly, but I do have bugs to
squish and need to figure out some portability issues.



Would you mind sharing what you have? I'm pretty good at figuring things out if I have a good working example to learn from.

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-08-2005 04:57

Sure! Right now I don't have time, when I do have time I will put it on my test server so you have a the working example and source code. I may want to make a few modifications to it before I move it.

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 11-12-2005 00:27

Actily my calendar needs more work than I thought... I suggest you look around Google or go here for examples to run off. I'm sorry, I can't give out any source until I release it under the GNU Licence. I do not know when that will be, maybe this year if I'm lucky!

« BackwardsOnwards »

Show Forum Drop Down Menu