bachx Posted February 26, 2007 Share Posted February 26, 2007 Alright, I want to create a time field in my MySQL DB where it acts as a countdown timer everytime I initiate it (Forum flood control, etc). This probably involves some SQL programming since the timer should still be running in the DB when the php script is not, but I haven't figured it out. So any help is appreciated. Quote Link to comment Share on other sites More sharing options...
Hooker Posted February 26, 2007 Share Posted February 26, 2007 If its for some kind of forum flood control you don't actualy need any kind of timer, try something like this: Add a "last post" feild to the user table then when they make a post have it ammend the current time to the feild and each post after just check against it with the current time and if the difference is only a few seconds/minutes (depending on what you want) don't save the post to the DB. Hope that makes sense Quote Link to comment Share on other sites More sharing options...
bachx Posted February 26, 2007 Author Share Posted February 26, 2007 Thanks for replying but that's not what I wanted. I only said flood control as an example, but I want it for a different reason. Anyone else? Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 26, 2007 Share Posted February 26, 2007 well tell us what you want it for and we can go from there unless its top secret and you are planning on taking over the world with the info you are seeking haha just kidding Quote Link to comment Share on other sites More sharing options...
bachx Posted February 26, 2007 Author Share Posted February 26, 2007 Well, I'm creating some kind of a game, and I want the player to wait some time (say 5 minutes) after he uses a certain features , before he can use it again. Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 26, 2007 Share Posted February 26, 2007 you might have to use javascript for "real time" and countdowns Quote Link to comment Share on other sites More sharing options...
bachx Posted February 27, 2007 Author Share Posted February 27, 2007 I want the countdown timer to be updated in the DB, so Javascript is a no. Anyone? Quote Link to comment Share on other sites More sharing options...
TRI0N Posted February 27, 2007 Share Posted February 27, 2007 Kinda fuzza what you mean by the need to post it in the database but you could just use SESSION to store the times then have your code look at the SESSION for the time it was used before it will allow it to be used again and once it is used again it will then update that SESSION variable. Less work load and faster. Quote Link to comment Share on other sites More sharing options...
bachx Posted February 27, 2007 Author Share Posted February 27, 2007 Hmmm..Sessions, didn't think of that. Thanks for your reply, will look into it. Quote Link to comment Share on other sites More sharing options...
bachx Posted February 27, 2007 Author Share Posted February 27, 2007 Ok I've just had a thought, what if the user logout (Destroy the session), then login back with a new session. That would reset the timers now wouldn't it? Quote Link to comment Share on other sites More sharing options...
TRI0N Posted February 27, 2007 Share Posted February 27, 2007 Only if you have the session close on logout.. But you don't have to close them if you don't want to.. But closing the browser will close them out.. Wouldn't the user not exit the game if they logged out? Quote Link to comment Share on other sites More sharing options...
bachx Posted February 27, 2007 Author Share Posted February 27, 2007 Wouldn't the user not exit the game if they logged out? Not really, it's not a real time or a turn based game, more like a MMO game, so the user can logout/login whenever he likes. That's why I need to store that timer somewhere, so I thought storing them in SQL was the only possible solution. Quote Link to comment Share on other sites More sharing options...
TRI0N Posted February 27, 2007 Share Posted February 27, 2007 Well you can store them I would just store date("H:i:s"). Quote Link to comment Share on other sites More sharing options...
bachx Posted February 27, 2007 Author Share Posted February 27, 2007 I do know how to store a date, I just need to know how to increment/decrement that date, kinda like a timer, in the database itself. So if the user is logged out, the timer would still be running in the DB. Quote Link to comment Share on other sites More sharing options...
TRI0N Posted February 27, 2007 Share Posted February 27, 2007 Well the DB isn't going to run a timer. It can store the time with UPDATE each time that a user clicks whatever option that is to be timed. Then have the code in the page look at that time and see if the time elapsed based on current time now. Quote Link to comment Share on other sites More sharing options...
heckenschutze Posted February 27, 2007 Share Posted February 27, 2007 Why not store the time they logged off as a UNIX TIMESTAMP and then compare it to the current timestamp when needed... eg: id | username | loggedoff (int) 1 | test | 68683782 Then find out how long its been since they logged off: $off = $row["loggedoff"]; $seconds_since_logoff = time() - $off; Quote Link to comment 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.