Jump to content

clear a table


Desaster

Recommended Posts

You can just check the date..something like this, although this code hasn't been tested

local nextClearDate = { } 
function checkDate ( ) 
    local t = getRealTime ( ) 
    local day = t['monthday'] 
    local month = t['month']+1 
    local year = t['year'] + 1900 
    if ( #nextClearDate <= 0 ) then 
        nextClearDate = {  
            day = day, 
            month = month, 
            year = year 
        } 
    end 
    if ( nextClearDate.year < year )then 
        executeClear ( ) 
    end 
    if ( nextClearDate.month < month ) then 
        executeClear ( ) 
    end 
    if ( nextClearDate.day < day and nextClearDate.month <= month ) then 
        executeClear ( ) 
    end 
end 
setTimer ( checkDate, 600000, 0 ) 
  
function executeClear ( ) 
    dbQuery ( databaseconnection, "DELETE FROM TableName" )  
    local t = getRealTime ( ) 
    local day = t['monthday'] 
    local month = t['month']+1 
    local year = t['year'] + 1900 
    nextClearDate.day = nextClearDate.day + 7 
    if ( nextClearDate.day > 30 ) then 
        nextClearDate.day = 1 
        nextClearDate.month = nextClearDate.month + 1 
    end 
    if ( nextClearDate.month > 12 ) then 
        nextClearDate.year = nextClearDate.year + 1 
        nextClearDate.month = 1 
    end 
end 
  
  

Edited by Guest
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...