Live MYSQL interactions?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daniel2335
    New Member
    • Dec 2007
    • 49

    Live MYSQL interactions?

    I’m attempting to program a text based online game using PHP and MYSQL, one of the pages will allow you to mine. This means the MYSQL will have a record of your mined resources and the remaining resources in the mine. On the page that controls the mining I would like a field with a live number showing how much has been mined and how much resources still remain. How do you think I could do this?

    If I was currently mining at a given rate would the database need to be updated constantly to keep track of what remained? Or could it record the time it started mining and if mining is stopped then calculate the mined resources and update only then? If so how do I keep a live track of this on the page for the user to see? (after a nice dynamic look).

    Maybe read the database when the page is loaded and then use javascript to update the page based on the rate and remaining resources it read from the database?

    This may be a problem as say the mining has been going long enough to completely mine the resources in the mine but the database hasn’t been updated with this information. Or even if say the rate of mining is changed in the database but as the javascript is predicting current status from the initial database read it will not reflect this change.

    Hope you guys know what I’m rambling on about, any help appreciated.

    Thanks
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    You could simply have an AJAX call update the database every few seconds (or whatever interval fits best), and have JavaScript edit what is shown when the updates are made.

    Having JavaScript estimate the changes and show them to the client between updates wouldn't even be that tricky.

    Comment

    Working...