Jump to content

Need help with auto increasement on a number in database


Dezmo

Recommended Posts

Hey im trying to make a small little game for my self at the moment, to test my self a little, the game i creating is based a little on the game http://ogame.org, im trying to find out how i can make the ressources auto increase on each member created on my site as the site ogame has, i dont need the javescript so you can see it auto increase, but just need to refresh it and then i can see that it has gone up, in my game im using Gold, Silver and Copper as ressources atm, and im not sure how to make the number in my database auto increase while the user have logged out, i was thinking about using some kind of function that would increse copper with 1 for each sec there goes with a timestamp or something like that, any of you guys knows how this could be possible? :)

 

Regards Dan Larsen

Link to comment
Share on other sites

I am not able to get your question.

 

you need to auto-increment for each registered member? if so then declare a primary key and set it to auto-increment in the DB itself. when you insert you dont have to send the primary key valuse the DB will increment it for you.

 

if this is not question - please explain it breifly.

Link to comment
Share on other sites

No its  like if you have 1 gold on your account and then make like 1 gold each sec, then when you get back into your account again your gold should be 26 if it was 25 secs ago you last checked your gold.

 

Simply put, the gold factor should raise by 1 for every sec there goes by.

Edited by Dezmo
Link to comment
Share on other sites

the time() function will return the number of seconds passed since the 1st January 1970. You can take advantage of that to count the seconds in an easy way:

// store the time they last checked for gold:

$last_gold_check = time();

// get the time when they check again:

$current_time = time();

// number of seconds will be final time - initial time:
$seconds = $current_time - $last_gold_check;

// update the gold count:

$availableGold += $seconds;

(or just skip the previous command and do it directly with $availableGold = $current_time - $last_gold_check)

 

(dont forget to update the last time gold was checked after this)

$last_gold_check = $current_time;

 

This seems like you're creating an incentive for people to keep refreshing the page... if every time they check for new gold it just adds the seconds from last check, you'll get people hitting the refresh button constantly just to see their gold increase.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.