Current location: Hot Scripts Forums » Programming Languages » PHP » Expire table data?


Expire table data?

Reply
  #1 (permalink)  
Old 09-22-04, 03:54 AM
bobby444 bobby444 is offline
Newbie Coder
 
Join Date: Jun 2003
Location: U.S.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Expire table data?

Sup all....

Is there anyway to set an expire time for table data/rows?

Like if i had a table like...
-------------------------------------------------------
Table_name: Table_Expire
|(Username)|(sumdata)|(expiretime)|
| Me | data | 1 hour |
| Me2 | data2 | 2 hours |
---------------------------------------------------------
So in 1 hour have the table row with user Me cleared/removed. and so on...
Kinda like having a cookie to expire... but using mysql instead.
Is there such a way to do this? or am I just thinking stupid? lol

Hope someone understands what im talkin about.. lol
Thanks for any help.
Reply With Quote
  #2 (permalink)  
Old 09-22-04, 08:14 AM
Bobbi Bobbi is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Looking into the mySQL manual, there doesn't seem to be a function like that - it's not really useful actually either. You would either have to use a cron (attention, can be CPU intensive if you have it running too often!) or just put a check in front of your scripts to clear the old data ...

A check could look like this ... stop putting "1 hour" or something into the database, use a unix timestamp (get it with time()) - now if you want the table to expire in 1 hour, you'd get the timestamp in hour with a command like
$exp_time = time() + (60*60)

Now if you store this timestamp in the database (use BIGINT for the field type), you could put a command like the following on top of your scripts which would simply clear out all expired lines:

$result = mysql_query("DELETE FROM Table_Expire WHERE expiretime > " . time());

Hope this helps, best regards,

Bobbi
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie MySQL fccolon PHP 2 03-16-04 10:54 AM
Creating data base table with visdata phil___23 Visual Basic 1 03-04-04 02:28 PM
copy data from table to it again ramez PHP 1 12-10-03 04:21 AM
moving data from table to table ..please help! geneane ASP 2 09-22-03 07:02 PM


All times are GMT -5. The time now is 04:30 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.