Solarpitch Posted November 6, 2006 Share Posted November 6, 2006 Hello!Ok . . I am developing a golfing website that allowes people to upload adds of there equipment they want to sell. They get a choice to have the add online for 1, 3, 5, 7, or 14 days.If the user selects thier add to run for lets say 5 days . . is thier anyway I can delete the record after the 5 days is up? Can that be done automatically? So if the add is uploaded on the 2nd December . . how do I add 5 days onto that for it to expire? ummm . . this one has really got me thinking!Cheers! Link to comment https://forums.phpfreaks.com/topic/26364-deleting-records-based-on-an-expire-date/ Share on other sites More sharing options...
Orio Posted November 6, 2006 Share Posted November 6, 2006 You can set a cron job that will run a script that deletes all the records needed from the database at midnight everyday for an example.Orio. Link to comment https://forums.phpfreaks.com/topic/26364-deleting-records-based-on-an-expire-date/#findComment-120545 Share on other sites More sharing options...
Solarpitch Posted November 6, 2006 Author Share Posted November 6, 2006 Umm . . thats sounds good! Except I have no idea what that is! How can I get the program to calculate the amount of time the add has been active for? Link to comment https://forums.phpfreaks.com/topic/26364-deleting-records-based-on-an-expire-date/#findComment-120548 Share on other sites More sharing options...
Orio Posted November 6, 2006 Share Posted November 6, 2006 Read a bit about crontabs [url=http://en.wikipedia.org/wiki/Crontab]here[/url].You need to check if you can run crontabs on your server, and if you can you just need to make the script to check if the are records that expired and if so delete them.Orio. Link to comment https://forums.phpfreaks.com/topic/26364-deleting-records-based-on-an-expire-date/#findComment-120554 Share on other sites More sharing options...
alpine Posted November 6, 2006 Share Posted November 6, 2006 Upon creating a new add, store the current time (example mysql NOW() will do) as [color=blue]date_added[/color] and the number of [color=blue]days[/color] to expire as number (like 5) (blue coloured names referring to my below example on col-names)Then you can run a query like this example in your script listing all adds, just run it on the top before querying to display adds:[code]<?php$sql = mysql_query("delete from table where date_added < date_sub(now(), interval (days) day)") or die(mysql_error());?>[/code]This is a solution if you cannot use cron for the job. Now, each time a visitor requests the file to display all ads, expired ads will be deleted first. Link to comment https://forums.phpfreaks.com/topic/26364-deleting-records-based-on-an-expire-date/#findComment-120559 Share on other sites More sharing options...
Solarpitch Posted November 6, 2006 Author Share Posted November 6, 2006 Thanks alpine . . thats a good idea!!! Link to comment https://forums.phpfreaks.com/topic/26364-deleting-records-based-on-an-expire-date/#findComment-120613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.