Jump to content

Archived

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

anthonydamasco

Expiration script For PHP

Recommended Posts

Hello there,

I've been googling this for a while, and I can't seem to ask the right question or find any answers, either way, I'm not getting anywhere.

The company I work for is a staffing agency, and they want a job search list, now I have to develop a database and an admin panel for our staff so they can add jobs to a "Job search" for employees. I pretty much can handle everything but 1 task. Setting an expiration date. If the job starts 1 month after It's posted, I want the to be a field on the admin panel where our staff could select "Sept. 9th 2006" and the job expires and removes itself for either the database or from the search.

I have some ideas on how this could work, for example perhaps I could set a field called Expiration and make it 0 or 1, and when the search it only brings up the results that have "expiration == 1" and then have a script that sets it so 1 with = 0 on a certain date or after a certain time.

If anyone could point me in the right direction as to the best solution I would appreciate it.

Share this post


Link to post
Share on other sites
Well, you can indeed ask after how many days in the admin panel but not on what date.
here is the way.
1. When one accesses a PHP script on the site you check the time() and compare it with the time stored (you need to have a column named time, where you store the time)
2. Compare the time of both and you can now know how many seconds have passed since the date it was put in.
3. If it is more than the time specified in expiry_date(now you also need this feild to have how many seconds after it has to be expired)
4. Add the time in DB and the expiry and compare it with the time.

Share this post


Link to post
Share on other sites
Alright so I should create 2 columns, one called time that I submit "time()" into and one called expire that I submit a date via form too. can you give me an example of what a simple script would look like with the two columns "time" and "expire", and lets say I wanted to set the time for 90 days after.

Share this post


Link to post
Share on other sites
$time=time();
$days='90'
$lapse=$days*24*60*60;
$expire=$time+$lapse;
INSERT INTO TABBLE (time, expire) values("$time","$expire")

That should input the current time in seconds and also the current time in seconds that it will be in 90 days

Your query for the search could be

$curtime=time();
SELECT * FROM table WHERE jobname='IT Admin' AND expire > '$curtime'

Regards
Liam

Share this post


Link to post
Share on other sites
Sorry my internet got bad, here is what i had to post.

The script which inserts data
takes post variable- job
[code]
<?php
// Considering, already connected to MySQL
$job = $_POST['job'];
$time = time();
$expiry = time() + 60*60*24*90;
$sql = 'INSERT INTO jobs(job, time, expiry_date, expire) values(\''.$job.'\', \''.$time.'\', \''.$expiry.'\', \'1\')';
mysql_query($sql);
?>
[/code]

Now the page where you delete, include this in any page so this automaically expires extra jobs.

[code]
<?php
// Considering connected to MySQL and have already put the job in
// $job, time in $time and expiry_date in $expiry
$time2 = time() - $expiry;
$sql = 'UPDATE jobs SET expire = \'0\' WHERE time>'.$time2;
mysql_query($sql);
?>
[/code]

Hope you understand it and it works

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.