Jump to content
Sign in to follow this  
Notretsam

countdown timers on webpage triggered by page activity.

Recommended Posts

Hope I explain this well enough for people to understand what am trying to do.

 

Am mostly a PHP developer and use mySql for database storage, so out of my element here.

 

I am working on a wrestling game and think I mostly got it worked out, however am struggling on "match countdown times"

 

I been Google searching on countdown timers and did suspect, that javascript would be needed and possible ajax.

 

There going be 2 to 4 players and each player will have a certain time before being counted out.

 

When the match is setup by someone, they can select from a variety off options for match length, 5mins, 1 day, 3 days, 5 days, 7 days etc.

 

Am trying to find a way to store a timer for each player in a database table, then output it on a page and show the time remaining for the player. lol I realize it not exactly an easy thing am trying to do, but really am at a lose on where to start here.

 

So any advice anyone can give me will be greatly appreciated.

 

I do need a way to convert the variables with the timer information over to PHP though.

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

As long as you save the start time to a table, you'll always be able display accurate elasped time.

 

Something like this will get you started:

 

https://mindgrader.com/tutorials/1-how-to-create-a-simple-javascript-countdown-timer

 

Else, google "javascript countdown clock" for more options.

Share this post


Link to post
Share on other sites

I did think of using time(); use that on any posts on sites, an use the following code to change time.

function timestampsw($original) {    // array of time period chunks    $chunks = array(        array(60 * 60 * 24 * 365 , 'year'),        array(60 * 60 * 24 * 30 , 'month'),        array(60 * 60 * 24 * 7, 'week'),        array(60 * 60 * 24 , 'day'),        array(60 * 60 , 'hour'),        array(60 , 'minute'),    );        $today = time(); /* Current unix time  */    $since = $today - $original;        // $j saves performing the count function each time around the loop    for ($i = 0, $j = count($chunks); $i < $j; $i++) {                $seconds = $chunks[$i][0];        $name = $chunks[$i][1];                // finding the biggest chunk (if the chunk fits, break)        if (($count = floor($since / $seconds)) != 0) {            // DEBUG print "<!-- It's $name -->n";            break;        }    }        $print = ($count == 1) ? '1 '.$name : "$count {$name}s";        if ($i + 1 < $j) {        // now getting the second item        $seconds2 = $chunks[$i + 1][0];        $name2 = $chunks[$i + 1][1];                // add second item if it's greater than 0        if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {            $print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";        }    }    return $print;}  

I include that page in and use below coding on page.

$timePost = timestampsw($testtime2);

I then get output like 3months, 2 weeks and so on.

 

$testtime2 would be filled with database field , which $time() would be added to.

Share this post


Link to post
Share on other sites

the website you linked in niche shows coding I saw on some other web pages , but that one walks you through it step by step, which could help me.

Share this post


Link to post
Share on other sites

Let us know.

Share this post


Link to post
Share on other sites

sadly I went to end of that page niche, copied the coding into a page, and added the script tags around it, didn't work for me. didn't really fill me with confidence when the end code on page doesn't work, so I moved on.

 

did come across this yesterday http://keith-wood.name/countdown.html , which did get working.

 

coding is similar to website u linked, an does work like it says, hard for me to recode it to do what I want though, as am not a javascript coder.

 

Also I realized today, I actually want timer for player to stop and only start again when it there turn.

 

I did work out coding for a "match timer" today and it works perfectly, used the timestamp function above to do that. so got an option to use a match timer instead of individual player timers. It not really what I wanted but does fit with wrestling, as time limits are usually on matches and not individuals.

 

I also came across this today http://snipplr.com/view/1524/

 

Certainly know using time() and storing it in a database is way to go on this. its just how to use that timestamp after retrieving it from database.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...