duanshan3065 2016-10-15 15:28
浏览 54
已采纳

Php jquery不会自动刷新div

I am trying to auto refresh a div which contains the Sub Total of item but its not working/refreshing the div. I tried many things but its not ready to work.

I am refreshing the Grand Total which updates/refreshes perfectly fine and if i removes a sub item of a main item it changes the Grand Total fine but does not change the Sub Total of the items.

enter image description here

I am using the separate refresh code for the grand total.

My codes are below:

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 } ?>
  • 写回答

1条回答 默认 最新

  • douhandie6615 2016-10-15 16:13
    关注

    I assume you want to update individual divs as you are running it within a loop.

    Try something like this

    <?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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路