Jump to content

Creating a countdown timer (SQL/PHP)


bachx

Recommended Posts

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

 

 

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.