[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.
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.
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.
You really need a function to do it, and I suggest a separate table instead
of using the DMax function.
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 " & _
Set DB = CurrentDb()
Set RS = DB.OpenRecordset(SQL)
If !DateStamp <> DateValue(Now()) Then
!DateStamp = DateValue(Now())
!Rec_Num = 1
GetRecNum = 1
GetRecNum = !Rec_Num
!Rec_Num = !Rec_Num + 1
Set RS = Nothing
Set DB = Nothing
For more information please visit six week industrial training in chandigarh
^ 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?
CREATE TABLE animals (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
INSERT INTO animals (name) VALUES
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
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread