Nov 21, 2009

How To Increment A Mysql Field At Regular Intervals?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > SQL (Structured Query Language)

How To Increment A Mysql Field At Regular Intervals?

FirefoxRocks
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?

Comment/Reply (w/o sign-up)

miCRoSCoPiC^eaRthLinG
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:
CODE
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.

Comment/Reply (w/o sign-up)

FirefoxRocks
In the Operations panel, I don't see an option to enter cron job scripts. Where do I put this in?

Comment/Reply (w/o sign-up)

Quatrux
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.

Comment/Reply (w/o sign-up)

Blaise
Use this command:

CODE
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.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for increasing, mysql
advertisement



How To Increment A Mysql Field At Regular Intervals?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com