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...
Mysql - Increase on certain times
Moderator: General Moderators
If you can run cron jobs on your server you can prepare a php script that updates the energy field every five minutes.
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.
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.
Code: Select all
// connect to database
// select database
// update records
// close databaseIf 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 databaseIf 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.
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..
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..