Jump to content
xisto Community
Sign in to follow this  
FirefoxRocks

How To Increment A Mysql Field At Regular Intervals?

Recommended Posts

I need an operation that involves increasing the MySQL field value of all records by 1 every 15 or 30 minutes. Since hundreds or thousands of records are present, there must be an automatic script/program that can do this. Think in terms of game sites which increase your army/gold every update. Basically I'm doing the same thing.How do I setup my database/table to do that?

Share this post


Link to post
Share on other sites

You'd probably need to run a simple script as a cron job. That's the only possible way I know of. Correct me if I'm wrong - but MySQL doesn't have inbuilt time based triggers.

The SQL statement that has to be run looks like:

UPDATE table_name SET the_field_to_update = the_field_to_update + 1;

This should update the required field for all of the records stored in the table in one go - producing exactly the effect you're looking for. However, the field needs to be numeric (INTEGER or DOUBLE) for this to work.

Share this post


Link to post
Share on other sites

If you're talking about PhpMyAdmin, of course not, to run cron jobs, you can use CPanel Cron Jobs, the unix style or standard, whatever you want, you'll need to have a file which does the operation you want and the right fields and tables to do it.

Share this post


Link to post
Share on other sites

Use this command:

mysql --user=username --host=host --password=password dbname < somefile.sql

somefile.sql should contain your SQL commands seperated with a semicolon.

I'm not sure if this'll work what it's worth a try.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.