簡體   English   中英

從ajax操作頁面到ajax調用頁面中顯示的總金額與ajax輸出表分開

[英]Display total amount from ajax action page to in ajax calling page separate from the ajax output table

如何在ajax返回輸出表的下面顯示銷售表中的總金額,然后如何在調用頁面中傳遞和接受?

Ajax操作頁面

$customer=$_POST["from_date"];
  $item=$_POST["to_date"];
  $quantity=$_POST["qty"];
  $ins=mysqli_query($connect,"INSERT INTO sale(pr_id,customer_name,item,quantity,sale_date) VALUES ('$item','$customer','$item','$quantity','$date')");
  $query="SELECT p.pr_name,  p.mrp, s.quantity,s.customer_name FROM sale s JOIN product p ON ( s.pr_id = p.pr_id ) WHERE s.customer_name = '$customer' AND p.pr_id = '$item'";
  $result = mysqli_query($connect, $query);  
  $output = '';  
if(mysqli_num_rows($result) > 0)  
{  $i=0;
  while($row = mysqli_fetch_array($result))  
       { 
            $output .= '  
                 <tr> 
                      <td>'.$i.'</td> 
                      <td>'. $row["pr_name"] .'</td> 
                      <td>'. $row["quantity"] .'</td> 
                      <td>'. $row["mrp"] .'</td>  
                 </tr>  
            ';  
              $output .= '  

            ';  
$i++;
       }  
  }  
  else  
  {  
       $output .= '  
            <tr>  
                 <td colspan="5">No Order Found</td>  
            </tr>  
       ';  
  }  

  $output .= ' <tr> 
  <td><?php echo $i++; ?></td>
  <td>'. $row["pr_name"] .'</td> 
  <td>'. $row["quantity"] .'</td>
  <td>'. $row["mrp"] .'</td> 
  </tr>    
  ';  
  echo $output;  
}  
?>

如何遍歷所有表單元格以及每一行的總數? 首先,給單元格一個我們可以引用的類(例如totalbox)

在jQuery中:

var total = 0;
$('.totalbox').each(function(){
    boxTotal = $(this).html();    
    total = total + boxTotal;
});
$('#some-other-div').html(total);

您可能需要將val解析為數字,很可能將其視為字符串。

暫無
暫無

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

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