SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: PHP Calendar

  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Calendar

    Hi all, I have managed to make a calendar that shows all of the dates in a month laid out appropriately. However, I need to add events to the calender. I would be able to do this if the event was a one-day event but they're not.

    I have an events table in my database that has a beginning and end date, so how can I put this onto the calendar, I guess I will need to use some sort of loop but unsure exactly how this can be done! Any help is appreciated as always

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,061
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    First you need to grab all events from you calendar that fall withing the current date. These are the events for which holds that:

    - Their end date is in the current month, OR
    - Their start date is in the current month, OR
    - Their start date is before the current month, and the end date is after the current month (i.e., an event that spans the complete month)

    (by "current month" I mean the month your calendar is currently showing)

    When you have these events, you just loop through the dates, and for each date check which of the events should be shown there.

    There may be different approaches, but this is the approach I took a while back, and it works just fine
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If every day in say, a 3 day event contains the same activities, at the same times, then ScallioXTX's solution will be fine.

    If every day in your event is different, then you could consider a solution whereby you make three one day events.

    Only you know the answer to this dilemma based upon your knowledge of the majority of types of events you will have to cater for.

    Overall, focus your attention more on how you are going to get your events out - more than how you are going to input and manage them.

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys, thanks for the pointers, much appreciated I'm just really stuck on how to get an event to fill each date column with the events until it reaches the events end date. There will be more than one event also in a month so I may have several events on one date, so how would I display this...using multiple loops?

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    So are you using start_date, end_date fields in your table, or are you using one entry per day?

  6. #6
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Cups, apologies for the long delays in replying, currently have limited internet access. Yes, I have a start and end date in my table...

  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey man, any further ideas on what I could do about this? Trying to build an availability calendar...

  8. #8
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Go to advanced search, search for calendar and limit the results to the PHP forums. There you will find a range of discussions.

    I do not personally use date_start, date_end style tables so cannot help you. Plenty of others do though.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •