簡體   English   中英

PHP jQuery無法自動刷新div

[英]Php jquery is not auto refreshing the div

我正在嘗試自動刷新一個div,該div包含項的Sub Total,但它不起作用/刷新div。 我嘗試了很多事情,但是還沒有准備好工作。

我正在刷新更新/刷新完全正確的總計,如果我刪除了主要項目的子項目,它將更改總計,但不會更改項目的子總計。

在此處輸入圖片說明

我正在使用總計的單獨刷新代碼。

我的代碼如下:

index.php

<?php
$order_temp =   mysql_query("select * from temp_cart where ses_mem='".$ses_mem."' order by id");

while ($torder = mysql_fetch_array($order_temp)) {
$prITTD     =   $torder['id'];
$prITTC     =   $torder['item_id'];
?>

<script>
function refreshTable() {
    $('.tableHolder').load('itemtotal_cart_checkout.php?item_id=' + <?php echo $prITTC; ?>, function() {
       setTimeout(function () { refreshTable() }, 1000);
    });
}
</script>

<div class="amount tableHolder">
</div>
<?php } ?>

itemtotal_cart_checkout.php

<?php
@session_start();
include('inc/db.php');
$ses_mem    =   $_SESSION['ses_user_id'];
//session_id();
$getItem    =   $_GET['item_id'];

$order_temp =   "select * from temp_cart where item_id='".$getItem."' AND ses_mem='".$ses_mem."' order by id";
$tordera = $db->query($order_temp);
while ($torder = $tordera -> fetch_assoc()){


    $prITTD     =   $torder['id'];
    $prITTC     =   $torder['item_id'];
    $prIDTC     =   $torder['price_id'];
    $qtyT       =   $torder['qty'];
?>
<span class="amount">
<?php   
$chTPaa =   mysql_query("
select choice_id
FROM temp_choices
WHERE item_id = '$getItem'
AND ses_mem = '$ses_mem'
group by choice_id
");
$numRows    =   mysql_num_rows($chTPaa);

while ($chGETaa =   mysql_fetch_assoc($chTPaa)){
$temp[] = $chGETaa['choice_id'];

$thelist    =   implode(",",$temp);
}
if ($numRows > 0){
$sumToCq1   =   mysql_query("
SELECT sum(p.price) as sTotal, t.item_id as item_id
FROM temp_cart as t, temp_choices tc, choice_price p
WHERE t.ses_mem='".$ses_mem."'
AND t.item_id = '".$getItem."'
AND tc.item_id = '".$getItem."'
AND p.id = tc.choice_id
");
$sumToC1 = mysql_fetch_assoc($sumToCq1);
$sumToNR = count($sumToCq1);
$choiceOptionsTotal1    =   $sumToC1['sTotal'];
    $tsl    = ($choiceOptionsTotal1*$qtyT)+($qtyT*$prIDTC);
}else{
    $tsl    = $qtyT*$prIDTC;
}

//number_format($tsl, 3);
$altsl  = number_format($tsl, 3, '.', '');
echo $altsl;
?>
</span>
<?php } ?>

我假設您要在循環中運行它時更新各個div。

試試這個

<?php
$order_temp =   mysql_query("select * from temp_cart where ses_mem='".$ses_mem."' order by id");
while ($torder = mysql_fetch_array($order_temp)) {
    $prITTD     =   $torder['id'];
    $prITTC     =   $torder['item_id'];
    $script    .= "refreshTable(".$prITTC.");";
    ?>
    <div class="amount tableHolder_<?=$prITTC;?>"></div>
    <?
}
?>

<script>
  function refreshTable(id) {
      $('.tableHolder_'+id).load('itemtotal_cart_checkout.php?item_id='+id, function() {
         setTimeout(function () { refreshTable(id) }, 1000);
      });
  }
  <?=$script;?>
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM