Jump to content


Photo

Expiration script For PHP


  • Please log in to reply
4 replies to this topic

#1 anthonydamasco

anthonydamasco
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts

Posted 14 August 2006 - 12:44 PM

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.


#2 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 14 August 2006 - 01:00 PM

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.
I am a PHP Guru, ask me questions if you want to

#3 anthonydamasco

anthonydamasco
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts

Posted 14 August 2006 - 01:08 PM

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.

#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 14 August 2006 - 01:27 PM

$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
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 14 August 2006 - 03:57 PM

Sorry my internet got bad, here is what i had to post.

The script which inserts data
takes post variable- job
<?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);
?>

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

<?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);
?>

Hope you understand it and it works
I am a PHP Guru, ask me questions if you want to




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users