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
Count Down timer
Moderator: General Moderators
Re: Count Down timer
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.
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.