Jump to content
MakeWebGames

[help] make this code works at the .tpl templates?


Fanatic

Recommended Posts

Can someone help me to do so that I can use this code in the tpl templates?

Cause i want to show how long time untill next energy refill.

 

// get the current minutes
$c_mins = date('i');
$c_secs = date('s');

// take the current minutes from 60 (60 minutes in an hour)
$l_mins = 60 - $c_mins;
$l_secs = 60 - $c_secs;

// Now we set up the message to be shown.
$time_left = 'There are ' . $l_mins . 'minutes and ' . $l_secs . 'left until ' . $n_hour . $m;

// echo the message we setup above
echo $time_left;

?>
Link to comment
Share on other sites

  • 2 months later...

Ok I have some code that can do this in javascript!!!

Create a blank file called countdown.php and paste the code bellow into it

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<script type="text/javascript" src="count.js"></script>

<link rel="stylesheet" href="static/default/style.css" type="text/css" />

</head>

<body>

<span id="count" class="timeClass"></span>

</body>

</html>

Now create a file called count.js and paste the code bellow to it

function countDown() {

var now = new Date();

var sec = 60 - now.getSeconds(); // set the seconds

var min = 59 - now.getMinutes(); // set the minutes

if (sec == -01) {

sec = 59;

min = min - 1;

} else {

min = min;

}

if (sec<=9) { sec = "0" + sec; }

time = (min<=9 ? "0" + min : min) + ":" + sec;

if (document.getElementById) { count.innerHTML = time; }

SD=window.setTimeout("countDown();", 1000);

if (min == '00' && sec == '00') {

min = "59";

sec = "60";

}

}

 

function countUp(){

var thetime=new Date();

var hours=thetime.getHours();

var mins=thetime.getMinutes();

var secn=thetime.getSeconds();

var day=thetime.getDay();

var AorP=" ";

if (secn<10)

secn="0"+nsecn;

if (mins<10)

mins="0"+mins;

if (day==0)

day="Sunday";

if (day==1)

day="Monday";

if (day==2)

day="Tuesday";

if (day==3)

day="Wednesday";

if (day==4)

day="Thursday";

if (day==5)

day="Friday";

if (day==6)

day="Saturday";

if (document.getElementById) { theTime.innerHTML = day+", "+hours+":"+mins+":"+secn; }

SD=window.setTimeout("countUp();", 1000);

}

 

function addLoadEvent(func) {

var oldonload = window.onload;

if (typeof window.onload != 'function') {

window.onload = func;

} else {

window.onload = function() {

if (oldonload) {

oldonload();

}

func();

}

}

}

addLoadEvent(function() {

countDown();

countUp();

});

Now finally where you want the count down to happen add in the code bellow

{include_php file='/home/ENTER YOU SITE USERNAME HERE/public_html/countdown.php'}

 

AND THIS SHOULD WORK

Edited by hutchy
Link to comment
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.

×
×
  • Create New...