内容更改时自动刷新仅显示多条记录中的一条

时间:2018-09-01 15:41:13

标签: javascript php ajax mysqli

下面的自动刷新代码没有给出错误,但刷新时仅显示多条记录中的一条。

但是当我包括但不刷新div时,它会显示所有记录。

像这样显示所有记录

<div class="m-timeline-3__items">
     <?php include('orders.php'); ?>
</div>

像这样显示一条记录:

<div id="newOrderRefresh" class="m-timeline-3__items">
</div>

orders.php

<?php
include ('inc/db.php');

$sqlx4  = "select distinct(order_id) as order_id from orders_placed where status = 0 ";
$sqlx5  = $dba2->query($sqlx4);
while ($sql6    = $sqlx5->fetch_assoc()){

    $sqlx1  = "select count(order_id) as total_items, order_id from orders_placed where status = 0 and order_id in ('".$sql6['order_id']."') ";
    $sqlx2  = $dba2->query($sqlx1);
    $sqlx3  = $sqlx2->fetch_assoc();

    $timeoid        = $sqlx3['order_id'];
    $totalItems =   $sqlx3['total_items'];
?>
<div style="width: 100%;" class="m-timeline-3__item m-timeline-3__item--info">
    <div style="margin-left: 41px; " class="m-timeline-3__item-desc">
        <div style="" class="m-timeline-3__item-text">
            Order # <font color="red"><b><?php echo $timeoid; ?></b></font>, 
            Total Items <font color="black"><b>( <?php echo $totalItems; ?> )</b></font>
        </div>
    </div>
</div>
<?php } ?>

var cacheData;
var data = $('#newOrderRefresh').html();
var auto_refresh = setInterval(
function () {
    $.ajax({
        url: 'orders.php',
        type: 'POST',
        data: data,
        dataType: 'html',
        success: function(data) {
            if (data !== cacheData){
                cacheData = data;
                $('#newOrderRefresh').html(data);
            }           
        }
    })
}, 1000);

0 个答案:

没有答案