Jump to content

Recommended Posts

Hello... i am currently making a website that is a browser game and im making a feature where you can only do somthing once every 2 minutes (120 seconds)... I need to know how i can make a timer so after u done somthing (im using a Form ) it sets a 2 minute timer..

 

im asuming you would have 1 field which is default at 0 and wen u have went to the next page with the form it will set this to 120 or somthing and if go on the page and that fied is > 0 it doesnt let u see it...

 

but i need to know how i make it so that Field goes down 1 a second?? or am i doing this totally wrong?

Link to comment
https://forums.phpfreaks.com/topic/183755-how-can-i-make-a-timer-for-my-database/
Share on other sites

Instead of setting it to 120, use a timestamp instead. Setting the database field to time()+60*2 would put that timestamp 2 minutes in the future, then when you check it, if the current time is less than that time stamp the user cannot re-post.

 

EDIT:

I am not sure what function you would use to mimic that in MySQL, but time is a PHP function.

When you do the update query you set the column that you want to be the time to that value:

 

UPDATE table_name SET col_time_log = NOW() + INTERVAL 120 SECOND WHERE userid = someid

 

Then if you want to see if the user has posted recently before insertion you can do this:

SELECT userid FROM table_name WHERE userid = someid AND col_time_log < NOW()

 

And if there is a row returned that user has posted within the 2 minutes and should not be able to post (given that I did my logic correctly).

 

EDIT:

Thanks mchl for pointing out how to do it in MySQL :)

Premiso, ive done what you said to do (with it changed a bit to fit my fields)

 

but its just set the field as '2009' and its not changing or anything at all...this is my code

 

  $timer = "NOW() + INTERVAL 120 SECOND";

$query2="UPDATE accounts SET VehicleTimer=$timer WHERE username='$accountname'";
$result2=mysql_query($query2);

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.