View Full Version : Cron? Timed events with PHP/SQL

11-17-2011, 03:25 AM
Hi guys. Read alot of threads here but havn't posted till now.

Im developing a little site just to give me something to do and experiment with, basically I have everything down with using php to add/edit/remove stuff from mySQL tables and user logins with sessions etc.

Its basically a mini ebay style that will never be used by anyone its just for me to practice development, basically a user can add an item, browse other peoples items etc etc. All the basic stuff

The next step I want to do is make the entrys (items) that people add to the database only last a week before being removed and needing to be relisted, the other option I need it for is for the item to be able to be "bidded on" which should be easy enough, and just need it to close bids being available after the set time limit, say 7 days again.

I havn't used Cron jobs before but if I had to guess im assuming I need a host that supports them? (hoping my current host does) or are there other options available.

Im by no means "advanced" or a programmer so im just looking for the easiest solution that works to get me started, if anyone could help out or least point me in the right direction for reading it would be appreciated it.

Thanks in advance

11-17-2011, 04:06 AM
Make a date field and set them as now().

PHP script that runs query to delete rows where current date is >7 days past the items date field.

You can run the PHP script as a cron job.

11-17-2011, 05:07 AM
for the inactive posting thing..

if u have a date_posted field, use unix timestamp time();

then in your php script do something like..

$query = mysql_query("select posting_id FROM postings WHERE date_posted > 604800"); // 7 days
while($f = mysql_fetch_array($query))
$id = $f[0];
mysql_query("DELETE FROM postings WHERE posting_id = '$id'");

then you can set up a cron job where it will run that every 7 days