Welcome Guest, Not a member yet? Register   Sign In
Ad expiration, How?
#1

[eluser]Mohsen32[/eluser]
Hello,
I am currently developing a classified ads, and I want the ads to be auto-expired after one month.
I'd appreciate any kind of help.
#2

[eluser]Dam1an[/eluser]
The easiest way would be to at a month to the current date when you insert the ad and then check this every time before displaying it

Code:
$next_month = mktime(0, 0, 0, date("m")+1, date("d"),   date("Y"));
#3

[eluser]Mohsen32[/eluser]
Thanks, worked.

How to set it to automatically check for expired ads? I mean, how to implement a automatic code which checks all ads everyday at 12 pm.
#4

[eluser]Dam1an[/eluser]
If you want something to run every day at a set time, the best/easiest option is to run a cron job (assuming you're on unix) or scheduled task (for Windows)
There's a Crob job entry on the wiki if you want to use for that, or you could just use a simple SQL query instead (although for some reason my brain just died and I can't even think in terms of SQL to give any hints)
#5

[eluser]Mohsen32[/eluser]
Thanks, I've found it, CronScript:
http://codeigniter.com/wiki/Category:Adv...ronScript/

Can you give me some info about the alternative SQL solution? Just in case I couldn't make it out of this Cron thing.
#6

[eluser]Dam1an[/eluser]
I'm not sure how you're determining which ones get retreived, but a where clause to make sure the expiration date is less then the current date is all thats needed.
Although you may need to occassionally purge the expired items if you get to have too many
#7

[eluser]Mohsen32[/eluser]
Ok, I get the where clause part and the less than stuff, But Is there a way to automate things using SQL?
#8

[eluser]Developer13[/eluser]
The easiest thing to do is track a unix timestamp of when the ad was entered. Then in your app, have it only display ads from the past 30 days -- so any ad older than 30 days would not be displayed. That way you don't have to run any jobs to expire the ads - instead your logic would be doing the work for you.
#9

[eluser]Zack Kitzmiller[/eluser]
This is really a simple thing to do, and there are hundreds of ways to implement it.

If I were going to do it, I'd have a column in the ads table in the database call 'status'. It would be an ENUM with two possible states, active and inactive. I'd also have a timestamp (i prefer unix timestamps, but you could do it with MySQL timestamps.

I'd setup a cron script to run a php file daily (or hourly or whatever) that checks to see if the timestamp on the ad is less than a month ago, if it is, then set the ENUM field to inactive.

That way you can leave all the bad entries in your db (in case they want to renew or whatever) but not allow then to display.

Then you can change all of the DB calls in your Models to include:
Code:
$this->db->where('status', 'active');
#10

[eluser]Developer13[/eluser]
No need for a cron script. Having to use one only further complicates things. Just limit the results being pulled by a parameter in the query. That's it.




Theme © iAndrew 2016 - Forum software by © MyBB