I have this javascript for displaying time counter :
$(function(){
var note = $('.note'),
ts = new Date(<?php echo $tgl_close1; ?>),
newYear = true;
if((new Date()) > ts){
newYear = false;
}
$('.countdown').countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " hari" + ( days==1 ? '':'' ) + ", ";
message += hours + " jam" + ( hours==1 ? '':'' ) + ", ";
message += minutes + " menit" + ( minutes==1 ? '':'' ) + ", ";
message += seconds + " detik" + ( seconds==1 ? '':'' ) + " <br />";
note.html(message);
}
});
});
i get the $tgl_close
value from database. It working fine if i just call 1 row from my table, but i need to make a multiply time counter by the result of database query.
this is how my table looked :
id | tgl_close1 | idrek
1 | 2014-11-25 08:00:00 | 1
2 | 2014-11-26 10:00:00 | 1
3 | 2014-11-26 12:10:00 | 1
i tried the stupid way by inserting the javascript into the foreach
loop but it didn't work..
this is how i tried :
<?php
$fetch = mysql_query("select tgl_close1
from tba
where idrek = 1");
/* Retrieve and store in array the results of the query.*/
while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
$tgl_close1[] = date("Y, n-1, j, G, i, s", strtotime($row['tgl_close1']));
}
foreach ($tgl_close1 as $tglclose){
?>
<br>
<table border="0"><tr><td>
<div class="countdown"></div>
<p class="note"></p>
</td></tr></table>
<!-- JavaScript includes -->
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="assets/countdown/jquery.countdown.js"></script>
<script type="text/javascript">
$(function(){
var note = $('.note'),
ts = new Date(<?php echo $tgl_close; ?>),
newYear = true;
if((new Date()) > ts){
newYear = false;
}
$('.countdown').countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " hari" + ( days==1 ? '':'' ) + ", ";
message += hours + " jam" + ( hours==1 ? '':'' ) + ", ";
message += minutes + " menit" + ( minutes==1 ? '':'' ) + ", ";
message += seconds + " detik" + ( seconds==1 ? '':'' ) + " <br />";
note.html(message);
}
});
});
</script>
<?php
}
}
mysql_close($conn);
?>
can someone show me how to do it?