Jump to content

Auto Delete Date Based Calendar Events


dizandat

Recommended Posts

Hello PHP Freaks Forum -

 

I am a new member here and have come with a purpose - I need some assistance with solving a problem.

 

Out of both wanting to improve my PHP skills and necessity, I created my own small CMS for a non-profit site I am involved with. One of the features I have is an event calendar where other users can submit  events, which then go into a "holding tank" until I can approve or deleted them. It's working great and everyone is loving it... but I have discovered one issue. When the date of the event passes, I have to log into the admin area and manually remove it. I am actually not deleting it from the database but changing a field variable and archiving it for our records.

 

I have been trying the past few days to come up with the necessary PHP to automatically check the current date (today's date) against all the calendar events and remove ones that have already happened. I could then hook this up to a CHRON action in my hosting CPanel and call it a day - at least that is how it all plays out in my head.  :)

 

I imagine in order to point me in the right direction you will need some information about my database.

 

Table Name:

calendar

 

Date Fields:

month  - char(2)

day - char(2)

year - varchar(4)

 

I am sure there was a much more logical way to set that up but as I mentioned above, this is my first big project like this so I have been learning to adapt along the way.

 

Thanks in advance for any help you can give me!

Link to comment
https://forums.phpfreaks.com/topic/47480-auto-delete-date-based-calendar-events/
Share on other sites

Why remove them at all?  Why not change your SELECT query so it only chooses records where the date is not less than today.  I'd suggest a change in the way you store dates - use one field, name date, type date (which will be yyyy-mm-dd) which you can display in your choice of date format.  Using yyyy-mm-dd allows you all sorts of very simple manipulation of the data.  Today is date("Y-m-d")

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.