2011-04-11 7 views
0

동적 자바 스크립트 카운트 다운 타이머를 만들고 싶습니다. SQL 서버 데이터베이스에서 datetime 변수를 전달하고이 날짜까지 카운트 다운 한 다음 메시지를 표시하고 싶습니다. 내가 찾을 수있는 거의 모든 jQuery 플러그인을 시도하고 내가 무엇을해야 그들을 편집 할 수있었습니다 havent 한, 나는 또한 어떤 도움이 많이 appriciated 될 것이다동적 자바 스크립트 카운트 다운 타이머 만들기

, 같은 페이지에 여러 카운트 다운 타이머를 할 수 있어야합니다

환호

스콧

======= 많은 시행 내가 이것을 수정할 수 있었다 오류 후 편집 =======

http://andrewu.co.uk/clj/countdown/pro/

내가

+7

누군가가 당신을 위해이 글을 쓰길 원한다면,보다 자세한 요구 사항을 제공하고 지불 체계를 수립해야 할 것입니다. 시도한 방법 중 하나에 문제가있는 경우 문제가되는 코드를 게시해야합니다. – Pointy

+0

그래, 그게 더 나은 접근 방법이었을 것이다. 나는 일을 그만 두면서 이것을 썼다. 많은 시행 착오 끝에 나는 이것을 수정했다. http://andrewu.co.uk/clj/countdown/pro/내가 필요한 것을 할 수 – Scott

+0

다른 사람들을 도울 수있는 방법으로 자신의 질문에 대답 할 수 있습니까? 그렇게하면 정답으로 자신을 선택할 수 있습니다. 이상하게 보일 수도 있지만, 이와 같은 상황을 처리하는 데 선호되는 방법입니다. – Will

답변

0

이 시도 필요로 무엇을 할 JS :

<body onLoad="Thick(20);"> 

희망 t : 같은 신체의 onLoad에서

function Thick(startin) { 
    startin--; 
    document.getElementById('timer').innerHTML = startin; 
    if(startin > 0) setTimeout('Thick(' + startin + ')', 1000); 
} 

호출하여 기능 그의 도움 :)

0
//TODAY'S DATE 
$today = time(); 
//FETCHES DATE AND TIME FOR THE EVENT FROM DATABASE 

$sql = "SELECT * FROM post"; 
$result = mysqli_query($conn, $sql); 
if (mysqli_num_rows($result) > 0) { 
$Row = (mysqli_fetch_assoc($result)); 
$th = $Row['endtime'];  
} 
echo $th 

first of all put it into a variable then use your javascript to call the variable 

//let get todays date here 
var today = new Date(); 
var DD = today.getDate(); 
var MM = today.getMonth()+1; //January is 0! 
var YYYY = today.getFullYear(); 
//let get the Difference in Sec btw the two dates 
var _DateFromDBProgEndDate = '<?php echo $th; ?>'; 
var ProgEndTime = new Date(_DateFromDBProgEndDate); 
var TodayTime = new Date(); 

var differenceTravel = ProgEndTime.getTime()- TodayTime.getTime() ; 
var seconds = Math.floor((differenceTravel)/(1000)); 
//////////////////////////////// 
var SecDiffFromToday = seconds; 
var seconds = SecDiffFromToday; 
function timer() { 
    var days  = Math.floor(seconds/24/60/60); 
    var hoursLeft = Math.floor((seconds) - (days*86400)); 
    var hours  = Math.floor(hoursLeft/3600); 
    var minutesLeft = Math.floor((hoursLeft) - (hours*3600)); 
    var minutes  = Math.floor(minutesLeft/60); 
    var remainingSeconds = seconds % 60; 
    if (remainingSeconds < 10) { 
     remainingSeconds = "0" + remainingSeconds; 
    } 
    document.getElementById('countdown').innerHTML = days + ":" + hours + ":" + minutes + ":" + remainingSeconds; 
    if (seconds == 0) { 
     clearInterval(countdownTimer); 
     document.getElementById('countdown').innerHTML = "Completed"; 
    } else { 
     seconds--; 
    } 
} 
var countdownTimer = setInterval('timer()', 1000); 
</script> 


the javascript call in the variable with '<?php echo $th; ?>'; then the javascript does the count down with out refreshing the page