Firtly, i select all data time from database, but when show to the page only the first one items will show the timer, other items cannot to show the timer.
<?php
$stmtAuction = $db->prepare("SELECT * FROM auction WHERE expired_at >= CURDATE() AND status = 'available' ORDER BY expired_at ASC");
$stmtAuction->execute();
if ($stmtAuction->rowCount() > 0) {
while ($item = $stmtAuction->fetch()) {
?>
<span id='countdown' value='<?php echo $item['expired_at'];?>'></span>
<?php
}
?>
<script>
$("#countdown").countdown($('#countdown').attr('value'), function(event) {
$(this).text(
event.strftime('%D days %H:%M:%S')
);
});
</script>
how can i show timer for every items??
$stmtAuction->rowCount()number ofid='countdown'.ids are supposed to be unique. So javascript/jQuery will only find the 1st/uniqueid='countdown'. You need to useclass='countdown', and$(".countdown"), although you will need to make some additional changes to make this work.idtoclass, as well as how to use$(".countdown")and$.each()to display each timer data.