Jump to content

Archived

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

ppunk

Filter Expired Classified Ad Listings

Recommended Posts

Hi, I am setting up an area on my site where users can post their own items they want to sell or give away, similar to a classified ad. I am having problems setting it up so it filters only active items. I want to set up the form so it allows the user to choose how many days their listing will be online (similar to ebay), like 7, 14, or 28 days as an example. After their item listing is expired, I want it so it is taken off the main site and put into an archive database table.
The only way I can think of doing this is to either put the code on the main listing page so it is run everytime someone views that page, or to set up a cron job to run every once in awhile. Items don't need to be taken down immediately, so in the case of me setting up a cron job to run every 6 six hours to check for expired items would be fine.

My main problem is, setting up the SQL and PHP to accomplish all this. I have had some help from some great members here, but I am still having trouble getting this to work properly and more importantly, actually learning how it works.

In my items database table, here are the fields I have right now:
id, startDate, endDate, type, summary (there are some more fields but they are irrelevant here).

Any help or tips would be great!
Thanks for any help in advance.

-Steve

Share this post


Link to post
Share on other sites
I would do it as a time diffrence

example

$start_date=date("dmy");

$end_date=date("dmy");

if($start_date>$end_date){

echo users info

elseif ($end_date - $start_date) {

insert to another table to be shown as an arcive

}

Share this post


Link to post
Share on other sites
I should have mentioned that I am not that advanced with php (yet). I am still learning little by little.
Is there anyway to explain a little more about how this can be done? You mentioned to do it as a time difference. Would it be a good idea to have the time included with the date? Right now my startDate and endDate are set up like this in my MySQL database: 2006-07-10.
Any help would be great.
Thanks for the reply!

-Steve

Share this post


Link to post
Share on other sites
I think the Cron job would be the best bet. Changing by page access would be unreliable if no-one visits the page.

Another solution would be to run a script that compares end date to today every time you add/edit/delete in your classified admin section, and then sets the status of the ad to inactive.

Share this post


Link to post
Share on other sites

×

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.