将产品价格与循环中的数量相乘

时间:2017-07-05 17:47:58

标签: 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 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
               }

如果在数据库中只有一条记录我得到正确的输出,但是如果我有两条或更多条记录,我的数字完全混乱

0 个答案:

没有答案