Hi,
I’ve got a javascript countdown timer that counts down to a time stored in a mysql database. Im passing the time from the database to the script using php. It works fine.
The problem is – I cant get it to accept variables from the current server time using php rather than the local time.
[url]http://asacarter.plus.com/marketplace/view.php?id=1
Here’s the working code:-
[code]
[head]
<? include(“common/connect.php”);
$end_query = “SELECT UNIX_TIMESTAMP(auction_end) FROM item WHERE id = $id”;
$end_result = mysql_query($end_query, $mysql_access);
@list($date) = mysql_fetch_array($end_result);
$year = date(Y, $date);
$month = date(n, $date);
$day = date(j, $date);
$hour = date(G, $date);
$minute = date(i, $date);
$second = date(s, $date);
echo “<script language=’javascript’>”;
echo “Year=”.$year.”n”;
echo “Month=”.$month.”n”;
echo “Day=”.$day.”n”;
echo “Hour=”.$hour.”n”;
echo “Minute=”.$minute.”n”;
echo “Second=”.$second.”n”;
echo “</script>”;
?>
<script type=”text/javascript” language=”JavaScript”>
function setcountdown(theyear,themonth,theday,thehour,themin,thesec){
yr=theyear;mo=themonth;da=theday;hr=thehour;min=themin;sec=thesec
}
setcountdown(Year,Month,Day,Hour,Minute,Second)
var montharray=new Array(“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”)
var crosscount=”
function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todayd=today.getDate()
var todaym=today.getMonth()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+” “+todayd+”, “+todayy+” “+todayh+”:”+todaymin+”:”+todaysec
futurestring=montharray[mo-1]+” “+da+”, “+yr+” “+hr+”:”+min+”:”+sec
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
if (dday!=1 && dday!=0) {
var SufDays=” days, “}
else if (dday<=0) {
var SufDays=””
var dday=””}
else {var SufDays=” day, “}
if (dhour!=1 && dhour!=0) {
var SufHour=” hours, “}
else if (dhour<=0) {
var SufHour=””
var dhour=””}
else {var SufHour=” hour, “}
if (dmin!=1 && dmin!=0) {
var SufMin=” minutes and “}
else if (dmin<=0) {
var SufMin=” and ”
var dmin=””}
else {var SufMin=” minute and “}
if (dsec!=1) {
var SufSecs=” seconds”}
else {var SufSecs=” second”}
if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(“Auction has ended”)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=”Auction has ended”
return
}
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(dday + SufDays + dhour + SufHour + dmin + SufMin + dsec + SufSecs)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=dday + SufDays + dhour + SufHour + dmin + SufMin + dsec + SufSecs
}
setTimeout(“countdown()”,1000)
}
</script>
[head]
<body onload=”start_countdown()”;>
<script type=”text/javascript” language=’javascript’>
function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility=”show”
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById(“countdownie”) : countdownie
countdown()
}
if (document.all||document.getElementById)
document.write(‘<span id=”countdownie” width: 300px; height: 12px;”></span>’)
</script>
Any idea’s on how I can get the server time rather than the local time?
Thanks,