DarrenReeder Posted December 2, 2009 Share Posted December 2, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/183755-how-can-i-make-a-timer-for-my-database/ Share on other sites More sharing options...
premiso Posted December 2, 2009 Share Posted December 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/183755-how-can-i-make-a-timer-for-my-database/#findComment-969904 Share on other sites More sharing options...
Mchl Posted December 2, 2009 Share Posted December 2, 2009 For MySQL it's NOW() + INTERVAL 120 SECOND Quote Link to comment https://forums.phpfreaks.com/topic/183755-how-can-i-make-a-timer-for-my-database/#findComment-969913 Share on other sites More sharing options...
DarrenReeder Posted December 2, 2009 Author Share Posted December 2, 2009 For MySQL it's NOW() + INTERVAL 120 SECOND so do i put this into a field of a record on my table? im confused on how i use it Quote Link to comment https://forums.phpfreaks.com/topic/183755-how-can-i-make-a-timer-for-my-database/#findComment-970097 Share on other sites More sharing options...
premiso Posted December 2, 2009 Share Posted December 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/183755-how-can-i-make-a-timer-for-my-database/#findComment-970114 Share on other sites More sharing options...
DarrenReeder Posted December 3, 2009 Author Share Posted December 3, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/183755-how-can-i-make-a-timer-for-my-database/#findComment-970619 Share on other sites More sharing options...
premiso Posted December 3, 2009 Share Posted December 3, 2009 What field type is VehicleTimer? As it will need to be a TIME or Datetime field for this to work as I have shown above. Quote Link to comment https://forums.phpfreaks.com/topic/183755-how-can-i-make-a-timer-for-my-database/#findComment-970634 Share on other sites More sharing options...
DarrenReeder Posted December 3, 2009 Author Share Posted December 3, 2009 ah yea, its working thanks! Quote Link to comment https://forums.phpfreaks.com/topic/183755-how-can-i-make-a-timer-for-my-database/#findComment-970647 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.