www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] How do I reset a column in my database every x days?

Hybrid View

  1. #1
    Join Date
    Mar 2014
    Posts
    8

    resolved [RESOLVED] How do I reset a column in my database every x days?

    Every x days (every 7 days for example), I would like all the values in a certain column in my MySQL database to reset back to '1'. How do I do this? I don't know how to write a program to do that, so please be specific. I'm just a beginner with PHP.

    Thanks!

  2. #2
    Join Date
    Jun 2007
    Posts
    400
    If you have access to the cron jobs on your server (usually through your control panel) you can just create a script that sets the column back to 1 when executed, and then schedule it to execute once a week or whatever.

    If you do not, you could do it in a sort of hacky way by putting some code on a page that you know gets hit a lot, store the date of the last update in your DB somewhere, and then check if it has been 7 (or more) days since the last update, if so, update again (and update your last update record as well.)

    But even writing that second one out makes me feel dirty. I'd do the cron job if possible.

  3. #3
    Join Date
    Mar 2014
    Posts
    8
    Thanks for your reply.
    Yeah, I tried doing your second suggestion but the code just got really messy. I don't have access to cron jobs on my server. I found a couple free sites that will do cron jobs for you (setcronjob.com) and that works.

    Thanks!

  4. #4
    Join Date
    Mar 2014
    Posts
    2
    You really need a function to do it, and I suggest a separate table instead
    of using the DMax function.

    Try this:

    The table will be RecNumTable with the columns EventID, DateStamp

    The function is below.
    --
    -
    Public Function GetRecNum() As Long

    Dim DB As DAO.Database
    Dim RS As DAO.Recordset
    Dim SQL As String

    SQL = "SELECT EventID, DateStamp " & _
    "FROM RecNumTable"

    Set DB = CurrentDb()
    Set RS = DB.OpenRecordset(SQL)

    With RS
    .MoveFirst
    If !DateStamp <> DateValue(Now()) Then
    .Edit
    !DateStamp = DateValue(Now())
    !Rec_Num = 1
    .Update
    GetRecNum = 1
    Else
    GetRecNum = !Rec_Num
    .Edit
    !Rec_Num = !Rec_Num + 1
    .Update
    End With

    Set RS = Nothing
    Set DB = Nothing

    End Function
    ---


    For more information please visit six week industrial training in chandigarh

  5. #5
    Join Date
    Jun 2007
    Posts
    400
    ^ You don't need to get that complicated when it is on a cron job though as long as you know you want it updated on a regular rhythm... the cron will take care of then when, all you need the code to do is the update.

    Most hosts will give you access to cron jobs... somewhere in the control panel. I think most will?

  6. #6
    Join Date
    Mar 2014
    Posts
    2
    CREATE TABLE animals (
    id MEDIUMINT NOT NULL AUTO_INCREMENT,
    name CHAR(30) NOT NULL,
    PRIMARY KEY (id)
    );

    INSERT INTO animals (name) VALUES
    ('dog'),('cat'),('penguin'),
    ('lax'),('whale'),('ostrich');

    SELECT * FROM animals;

    +----+---------+
    | id | name |
    +----+---------+
    | 1 | dog |
    | 2 | cat |
    | 3 | penguin |
    | 4 | lax |
    | 5 | whale |
    | 6 | ostrich |
    +----+---------+

    For more please visit six week industrial training in chandigarh

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles