[英]i am making Point of Sale and i want to get nettotal of the products, using ajax but i am having trouble in it
this is my javascript 这是我的javascript
<script>
function multiply(id) {
var quantity = $("#quantity"+id).val();
var price = $("#price"+id).text();
var dataArray= 'quantity1='+ quantity + '&price1='+ price;
$.ajax({
url: "ajaxmultiply.php",
data: dataArray,
type: 'POST',
success: function (data) {
$("#total"+id).(data);
}
});
}
</script>
I am able to get the total of the products but i am having issue in getting net total of the product, i am doing this using ajax
, when i add the total it will give me previous value as concatenated with next value,i tried using through array but it also didn't work, now i store the total value in new table and then fetch it from there and add it but i didn't give me required answer, i tried to use array in it but it also didn't work for me 我能够获得产品的总数,但是我在获取产品的净总数时遇到问题,我正在使用
ajax
进行此操作,当我添加总数时,它将给我先前的值与下一个值的连接,我尝试使用通过数组,但它也不起作用,现在我将总值存储在新表中,然后从那里获取并添加它,但是我没有给我所需的答案,我尝试在其中使用数组,但它也没有为我工作
This is my ajaxmultiply.php
file code 这是我的
ajaxmultiply.php
文件代码
<?php
include 'connection.php';
$quantity=$_POST['quantity1'];
$price = $_POST['price1'];
$total= $quantity * $price;
//echo $total;
$query =mysqli_query ($conn,"INSERT INTO grand_total (total) VALUES
('$total')");
$getdata=mysqli_query($conn,"SELECT * FROM grand_total");
while ($fetchdata=mysqli_fetch_assoc($getdata)){
$newtotal = $fetchdata['total'];
$id = $fetchdata['id'];
$grandTotal=$newtotal + $newtotal;
echo $grandTotal;
}
Your while loop should be like below: 您的while循环应如下所示:
$grandTotal = 0;
while ($fetchdata=mysqli_fetch_assoc($getdata)){
$newtotal = $fetchdata['total'];
$id = $fetchdata['id'];
$grandTotal += $newtotal;
}
echo $grandTotal;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.