How can I change the value of a row in a database everyday?
Eg: I have a column for balance, the default is 20, every time the user uses their balance it decreases. I want to change it every 12am to 20 again. How can I do that?
Thanks, H
Change value on database every 12mid night
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Change value on database every 12mid night
Write a cron job that processes a script that will login to the database and reset that value every day at 12.
Re: Change value on database every 12mid night
Generally it's a bad idea to update a database based on a time interval. The better approach is to have a field in the table where the current date/time is stored each time that record is updated (or that field, if that's the logic). Then whenever you check a record for the balance, you compare the current date with the date last updated and if it's earlier than "today" you adjust the balance at that time. There's no need to constantly update all the records in the table.Argie wrote:How can I change the value of a row in a database everyday?
Eg: I have a column for balance, the default is 20, every time the user uses their balance it decreases. I want to change it every 12am to 20 again. How can I do that?
Thanks, H
Last edited by califdon on Sat Dec 20, 2008 2:36 pm, edited 1 time in total.
Reason: Reworded for clarity.
Reason: Reworded for clarity.
Re: Change value on database every 12mid night
thx to you all and to cron 