我想在javascript代码中打印数据库中的日期列
这是我想要更改日期倒计时的原始javascript代码
<link rel="stylesheet" type="text/css" href="display.css" />
编辑后的代码:
</head>
答案 0 :(得分:0)
如果你只有数据库中的一个值,你就不需要循环任何东西了,虽然我无法想象你有一个专用于一行的整个表,除非你有一堆记录的行,在这种情况下,您可能应该限制返回一行。无论如何,它可能看起来应该更像这样:
<?php
# You probably just need to limit 1 and only select the column you need
$query = $DB_con->prepare("SELECT `dateauction` FROM `auction` ORDER BY id DESC LIMIT 1");
$query->execute();
# Just fetch without a loop
$row = $query->fetch(PDO::FETCH_ASSOC);
?>
<script type="text/javascript">
$(document).ready(function() {
// You should probably have quotes and a semicolon, also only one equal sign
var countdw = '<?php echo $row['dateauction'] ?>';
$('#countdown').countdown(document.write(countdw), function(event) {
$(this).html(event.strftime('%H:%M:%S'));
});
});
</script>