Change value on database every 12mid night

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Argie
Forum Newbie
Posts: 2
Joined: Sat Dec 20, 2008 12:14 am

Change value on database every 12mid night

Post by Argie »

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
User avatar
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

Post by RobertGonzalez »

Write a cron job that processes a script that will login to the database and reset that value every day at 12.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Change value on database every 12mid night

Post by califdon »

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
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.
Last edited by califdon on Sat Dec 20, 2008 2:36 pm, edited 1 time in total.
Reason: Reworded for clarity.
Argie
Forum Newbie
Posts: 2
Joined: Sat Dec 20, 2008 12:14 am

Re: Change value on database every 12mid night

Post by Argie »

thx to you all and to cron :D
Post Reply