Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> How To Increment A Mysql Field At Regular Intervals?
Rating 5 V
FirefoxRocks
post Apr 22 2007, 01:01 AM
Post #1


Super Member
Group Icon

Group: [HOSTED]
Posts: 660
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



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?
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Apr 23 2007, 04:59 AM
Post #2


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



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.
Go to the top of the page
 
+Quote Post
FirefoxRocks
post May 5 2007, 06:37 PM
Post #3


Super Member
Group Icon

Group: [HOSTED]
Posts: 660
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



In the Operations panel, I don't see an option to enter cron job scripts. Where do I put this in?
Go to the top of the page
 
+Quote Post
Quatrux
post May 6 2007, 09:59 AM
Post #4


the Q
Group Icon

Group: [HOSTED]
Posts: 1,022
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059



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.
Go to the top of the page
 
+Quote Post
Blaise
post Nov 4 2007, 02:23 PM
Post #5


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 28
Joined: 4-November 07
Member No.: 25,937



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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Constraints Don't Work In Mysql?(11)


 



- Lo-Fi Version Time is now: 8th September 2008 - 10:15 AM