0

I have an entry in my database, and when a certain date hits I want to update the entry.

Here's an example:

+----+----------+-------------+---------+
| id |  title   |  exiryDate  |  status |
+----+----------+-------------+---------+
| 23 | my title | 10-Sep-2013 |  active |
+----+----------+-------------+---------+

My code is written in PHP and the idea is that when the date hits 10th September, the 'status' of the entry will update to expired instead of active.

How could I update the entry in DB based on date?

I suppose I could run a check on page load every time someone visits the page, but what if I want to update the entry without someone necessarily visiting the site or the web page?

Allen S
  • 3,471
  • 4
  • 34
  • 46

1 Answers1

0

you'll need to create a cron job that checks the date and updates your db. It's pretty easy to do if you have a control panel from your web host.

Just create a PHP script that does what you want, then set the cron scheduler to run that script when you want.

Just create the PHP script with the code you want, and put this at the very top

#!/usr/bin/php -q
<?php
// put your script here

Save the file and CHMOD it to 755. After that you can set your cron job

Finding the cron manager on GoDaddy: http://answers.yahoo.com/question/index?qid=20120523092508AA2vOUU.

timgavin
  • 4,972
  • 4
  • 36
  • 48
  • Hey Tim, thanks for the reply. I'm new to cron - so help is much appreciated :). I'm using GoDaddy. I've created a Cron Job (will run every day). I've also created my PHP script that will update the DB. I'm not sure how to link my PHP to the cron job i created. It asked me to enter a command when creating a Cron Job, but how do I link this command to the PHP file? – Allen S Sep 07 '13 at 02:54
  • you select the PHP file, or enter the full path to it. I can't tell you exactly because each host has different paths and control panels, so you'll have to look that up to see how GoDaddy wants it done. I've updated my answer as well. Also, to make sure your cron job is working, I usually just put a simple mail() function in it and run the cron job every 3 minutes. If it runs and I receive an email I know it's working, so i replace that with my real script :) – timgavin Sep 07 '13 at 03:03