What I want to do is have a value displayed in a php file which is stored in a MYSQL database. This value needs to be updated every second (by a mathematical operation), then changed in the browser, and updated to the mysql table.
I am open to other ideas other than MYSQL to store this value. Keep in mind, though, that there will be thousands of these values that need to be updated in this manner.
I’m not trying to blow up my server here, so help me optimize this!
What I need to do is have a text field which holds a number to increase by a specified value every second. The values in this text field need to be the same when the page is closed and reopened again, possibly being stored in a mysql database maybe.
The database will update the text box, which displays the “clock” as he mentioned. I need the value of the text box to update even when the page is not being viewed, or else update to the correct amount the next time the person views the page again.
You said you’re stored value is achieved by “mathematic calculation”.
Store both your value and a last calculated server timestamp.
When you load the page collect this value and the timestamp from the database. Use the current server time to calculate the difference since the last calculation.
Difference = CURRENT TIME - STORED TIME
Calculate the new value. Should the value have any reliance on the previous value you can rely on a for loop here, otherwise you can rely on simple calculation and multiply it by your difference.
Update the database with your new value and your new timestamp (the current time, not the difference). Ensure you store the time at which your difference was calculated from. Otherwise, if your calculation took three seconds for example during a server lag or something, your future counts will be inaccurate.
Output your value to the browser however and wherever you need it.
EDIT: This’ll seriously reduce database usage and bandwidth. Anything not completely clear or your not sure about just reply =]