Php 将产品价格乘以while循环内的数量
我试图用while循环中的数量乘以产品价格Php 将产品价格乘以while循环内的数量,php,mysql,arrays,sum,inner-join,Php,Mysql,Arrays,Sum,Inner Join,我试图用while循环中的数量乘以产品价格 $sql = "SELECT c.cart_id, c.product_id, c.company_id, c.quantity, c.unique_id, c.email, c.time, p.product_id, p.product_name, p.price, p.thumb_src, m.company_id, m.company_name FROM cart AS c INNER JOIN product AS p INNER JOIN c
$sql = "SELECT c.cart_id, c.product_id, c.company_id, c.quantity, c.unique_id, c.email, c.time, p.product_id, p.product_name, p.price, p.thumb_src, m.company_id, m.company_name FROM cart AS c INNER JOIN product AS p INNER JOIN company AS m WHERE c.product_id=p.product_id= c.company_id=m.company_id"; // Selecting the price from the product table
$stmt = mysqli_prepare($dbc, $sql);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$total = 0; // defining the total as 0
mysqli_stmt_bind_result($stmt, $cart_id, $product_id, $company_id, $quantity, $unique_id, $email, $time, $product_id, $product_name, $price, $thumb_src, $company_id, $company_name); // binding the parameter
while(mysqli_stmt_fetch($stmt)){
$subtotal = $quantity * $price;
$total += $subtotal
}
如果在DB中只有一条记录我得到了正确的输出,但是如果我有两条或更多的记录,我的数字就完全搞乱了;之后+=$subtotal@clearshot66哦,这与此无关)但无论如何,谢谢)从数学上看,它看起来很好,告诉我们你的实际输出是什么以及你在寻找什么。@clearshot66看,在我的购物车表中,我有不同的产品,一个数量为1,另一个数量为1,价格是8.00和9.00,在输出中我得到18.00和26.00,总的来说我得到26。00@clearshot66如果你有teamviewer,我可以给你看