Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hourly update of database via PHP

Status
Not open for further replies.

OOP

Programmer
Feb 5, 2001
94
0
0
SG
Hello,
Not sure whether this is done on the PHP or MySQL side. What i would like to do is to have the numbers stored in database (MySQL) to change hourly according to a formula.
Is there such a function in PHP or MySQL? Any help/comment would be appreciated, thanks.
 
What numbers are we talking about?
eg. can you provide some more information on what you want to do? When do you want it to be done, etc.

eg. change to x when time is y, etc.

Olav Alexander Mjelde
Admin & Webmaster
 
To elaborate, pls consider the following example;

I have a table containing the numbers of items i'm having now, money and food etc.
The scenario is that the food is decaying at every hour and i'm earning some amt. of money at the same hour. Let us assume that i earn 10 unit of money and lose 1 unit of food per hour, how do i make the database to update the amount hourly itself.
 
There are several ways to approach this one. In most cases.. its best to do stuff like this with your scripting language not your DB. Not knowing anything about your situation, its hard to give you a clear direction to go.

I'm guessing this would be a number that would be different for each item. If so, in your DB, store the date added and the decay rate. Then just use the date() function in php to do some math and figure it out. Just remember, php stores datetime fields in the format of "YYYY-MM-DD hh:mm:ss".. using strtotime() on your varible from mysql should be a help. This will convert it to a php date that you can compare things on.

-Dustin
Rom 8:28
 
ah, so you are making some kind of tick-based game?

In this case, you have to decrease x fields by the value y, every z hrs.

I've never tried using php/crontab, but maybe you can use perl/crontab?

I think people usually depend on perl, when running crontab. ps. I might be mistaken here!

I would recommend googling on the subject.

please post back what you figure out here, as I find this topic very interesting.

You could also try searching for php tick-based games, and look at source.. eg. what do they do to update ticks?

Olav Alexander Mjelde
Admin & Webmaster
 
Thanks for the response so far..
And for DaButcher, yes, i'm currently in progress in developing an online tick-based game. I think we couldn't see the php source code for the other games right? We could only see the output html code if we view source, if i'm not mistaken..unless there's some sort of configuration error on the server side[ponder]

Will update again.
 
In the interest of open source, I'm sure you'll find sample code, ie: sourceforge.net and such...The Refugee
 
Here's another idea...

rather than updating every hour or so... add a datetime field which you set everytime you write the information to the database.

Then, instead of automatically doing everyone every hour, you can wait until you make a read of the row, if the timestamp is greater than some threshold, then you run the formula based on the amount of time which has passed since the timestamp.

The only downside to this method is if you want to do something like calculate the total wealth or food supply for economic purposes.

Otherwise... on the linux side look into cron, and in the windows side, look into AT or the windows scheduler... all those options will allow you to schedule a PHP script to run using the command line interpretter at any times you like... using this method I would still suggest using the timestamp approach in case you miss an execution due to a power outage or an otherwise down system.

 
skiflyers way might work..
it's good in theory, but there might be some issues if it is some kind of attack/revenue game, with something increasing and/or decreasing each tick.

you can run a mysql command to update fields.
the mysql command can be run thru perl or php, via crontab.

Olav Alexander Mjelde
Admin & Webmaster
 
Have read thr stuff like cron and wincron. Seems like its the best solution for my problem..Hope that there's web host supports cron jobs.
As i'm currently designing the game in windows enviroment, i might have to manually update the database with the formula..and Wincron doesn't available as freeware also [sad]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top