在mysql_fetch_assoc中打印时出错

时间:2017-12-02 13:57:08

标签: javascript php html

在此代码中,将打印倒计时 该值来自数据库,但是在打印时 他只打印第一行中最后一行的值,而不打印另一行的值

while ($row = mysql_fetch_assoc($dave)) {
 $rows[] = $row; 
} 

foreach($rows as $row) {
    $all=$row['date'];

echo '<h2>'.$row['title'].'</h2>';
    echo '<h4>'.$row['body'].'</h4>'.'<br>'."<script> var res = \"<?php echo $all; ?>\";
var dateVar = res.substring(11, 21); 
var countDownDate=new Date(dateVar).getTime();

var dsplit = dateVar.split(\"-\");
countDownDate=new Date(dsplit[0],dsplit[1]-1,dsplit[2]).getTime();

// Update the count down every 1 second
var x = setInterval(function() {

    // Get todays date and time
    var now = new Date().getTime();

    // Find the distance between now an the count down date
    var distance = countDownDate - now;

    // Time calculations for days, hours, minutes and seconds
    var days = Math.floor(distance / (1000 * 60 * 60 * 24));
    var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);

    // Output the result in an element with id=\"demo\"
    document.getElementById(\"demo\").innerHTML = days + \"d \" + hours + \"h\"
    + minutes + \"m \" + seconds + \"s\";

    // If the count down is over, write some text 
    if (distance < 0) {
        clearInterval(x);
        document.getElementById(\"demo\").innerHTML = \"EXPIRED\";
    }
}, 1000);

</script>
";

0 个答案:

没有答案