Count Down timer

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
cpeckvt
Forum Newbie
Posts: 1
Joined: Thu Oct 30, 2008 11:38 pm

Count Down timer

Post by cpeckvt »

Hello
I am trying to code a countdown timer like the ones you see on facebook games such as Mobwars, Crusades and other games.
I need a timer that counts down from 300 to zero. here is the code I have writtern so far.

$energy = $row['energy'];
$max_energy = $row['max_energy'];
$energy_time = $row['energy_time'];[/b]

$now = time();
$user = 1;
if ($energy != $max_energy) {
$energy_time2 = $energy_time + 300;
$time = $now - $energy_time;
$time2 = 300 - $time;
if (( $time <= $energy_time2) && ($time2 >= 0)) {
echo ("Regen. Energy in <font color=\"E2C70D\" size=\"1\" face=\"verdana\">".$time2."</font> sec.");}
if ($now >= $energy_time2) {
mysql_query("UPDATE skills SET energy_time='$energy_time2' WHERE user_id='$user'");
$energy = $energy + 1;
mysql_query("UPDATE skills SET energy='$energy' WHERE user_id='$user'");
echo ("Regen. Energy in <font color=\"E2C70D\" size=\"1\" face=\"verdana\">".$time2."</font> sec.");
if ($energy != $max_energy) { echo "You Have Full Energy!"; }

I am getting stuck with the negative numbers.
When $time is more then 300 the result is a negative number, big problem.
can someone help me or point me in the right directon
CP
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Count Down timer

Post by califdon »

I have moved this topic to Client Side.

PHP code is executed in the server, so it cannot know anything that happens after the page is sent to the browser. You need Javascript.
Post Reply