My code
$sql="SELECT * FROM `room_lists`";
$sqlquery = mysql_query($sql);
while($result = mysql_fetch_array($sqlquery)){
$toDay = strtotime($result['timeStop']);
//echo $toDay;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis620" />
<script type="text/javascript" src="core/jquery-latest.js"></script>
<title>test</title>
<script type="text/javascript">
function countDown(times){
var toDay=Math.round(new Date().getTime()/1000);
var difTime=times-toDay;
var day=0,hours=0,minutes=0,seconds=0;
if(difTime>0){
day=Math.floor(difTime/84600);
hours=Math.floor((difTime/3600))%24;
minutes=Math.floor(difTime/60)%60;
seconds=Math.floor(difTime)%60;
countDown_onLoad();
}
else{
alert('asd'); //time out
}
$('.show').html(day+' Day '+hours+' Hour '+minutes+' Min '+seconds+' Sec ');
}
function countDown_onLoad(){
setTimeout("countDown(<?=$toDay ?>);",1000);
}
$(document).ready(function() {
countDown_onLoad();
});
</script>
</head>
<body>
<div class="show"></div>
</body>
</html>
<? } ?>
Hello, I am a newbie using javascript. I have created countdown timer to use like auction website with js function that call from database(timestamp type) with php query, if the result is 1 row, it works fine but if more than 1 the result are all the same as last row in database. How can I fix this?
This is my output
0 Day 1 Hour 41 Min 25 Sec
0 Day 1 Hour 41 Min 25 Sec
You appear to be outputting an entire HTML document (less the opening
<html>tag and<!doctype>) for every counter.The core problem is that you are using
$(".show").html(...)to output the counter, which is essentially telling it to put that content in every.showelement. The net result is that they all show the same thing: whatever the last counter is at.Your approach is almost unsalvageable, but here is my best attempt:
Please note that I do not use jQuery. I am only using it here because you were already using it. With that in mind I may have incorrectly used
.each(). Please let me know if you encounter any errors and I will try to fix them.