-2

I need to automatically count down a php variable -1 every 5 seconds displayed in the title oft the page and automatically update eg. title: '23/30 Auto Battles Remaining'.

Is this possible to do in php/jquery? Any help would be appreciated.

Thanks in advance.

sk1p
  • 1

1 Answers1

1

In PHP - not possible
In JS (you can't do it in *.js file)

var counter = <?php echo $currentGames; ?>,
counterTimer,
totalGames = <?php echo $totalGames; ?>;

counterTimer = setInterval(reCounter(), 5000);

function reCounter() {
    window.title = counter + '/' + totalGames + ' Auto Battles Remaining';

    if (counter <= 0) {
        clearInterval(counterTimer);
    }
    counter--;
}
Justinas
  • 41,402
  • 5
  • 66
  • 96
  • The number will not always be 30, I selected the "30" from a field in the db. current battles/total battles, part I was having trouble with is getting the php int he title with js :/ – sk1p Aug 08 '14 at 10:45
  • @sk1p so your numbers comes from PHP side and you want to check it every 5 seconds? – Justinas Aug 08 '14 at 10:49
  • Yes, just needs to select the number from php side and minus by 1 every 5 seconds and automatically refresh in the page title/tab. Thank you for your help so far I appreciate it. – sk1p Aug 08 '14 at 10:54
  • I couldn't get it to work :/ – sk1p Aug 08 '14 at 12:02