Page 1 of 1

Mysql - Increase on certain times

Posted: Mon Jul 04, 2005 12:51 pm
by Terriator
Hey all...

My question is this; Say I'm creating a rpg, and want the all users' energy in the energy-field in the database to increase by 1 every 5 minutes..

What would be the best way to do this?

/Thanks in advance...

Posted: Mon Jul 04, 2005 12:55 pm
by delorian
If you can run cron jobs on your server you can prepare a php script that updates the energy field every five minutes.

Code: Select all

// connect to database
// select database
// update records
// close database


If you cannot use cron you will probably have to run script manually or refresh the web page of (I asume your rpg is browser-based-application) your rpg system.

I believe that it could be done with stored procedures without using PHP, but those will be available in MySQL 5.x, AFAIK.ose database :)


If you cannot use cron you will probably have to run script manually or refresh the web page of (I asume your rpg is browser-based-application) your rpg system.

I believe that it could be done with stored procedures without using PHP, but those will be available in MySQL 5.x, AFAIK.t updates the energy field every five minutes.

Code: Select all

// connect to database
// select database
// update records
// close database


If you cannot use cron you will probably have to run script manually or refresh the web page of (I asume your rpg is browser-based-application) your rpg system.

I believe that it could be done with stored procedures without using PHP, but those will be available in MySQL 5.x, AFAIK.
// connect to database
// select database
// update records
// close database :)


If you cannot use cron you will probably have to run script manually or refresh the web page of (I asume your rpg is browser-based-application) your rpg system.

I believe that it could be done with stored procedures without using PHP, but those will be available in MySQL 5.x, AFAIK.

Posted: Mon Jul 04, 2005 1:07 pm
by timvw
Why do you need to update them all the time?

Just store the (initial_datetime, initial_score)

And then calculate as following:

current_score = (current_datetime - initial_datetime) * increment + initial_score

Now you only have to update if something changes that is initiated by a user generated event...



For performance reasons you could add some redundant columns like last_calculated, last_score and use those values if they are still valid..

Posted: Tue Jul 05, 2005 3:53 am
by Terriator
Thank you =) ...

You're right, it isn't neccesay to update them all, all the time..

I got it made now =) ..

/Cheers!