获取PHP中特定列下的值之和

获取PHP中特定列下的值之和,php,mysql,invoice,Php,Mysql,Invoice,请帮忙 我想得到列中所有值的一个和,Totalamt 它将显示在总计下: 有人能帮忙编码吗,因为总金额值是通过减法乘法获得的,因为折扣等原因,而不是像我看到的其他来源那样简单地定义为$row['totalamt'] 发票 您是否尝试过使用像total_amount这样的变量,并在for循环之前声明它,只需在其中添加数量并在循环之后显示它 <body> <?php if (isset($_POST['submit'])) { $name_array = $_POST

请帮忙

我想得到列中所有值的一个和,Totalamt 它将显示在总计下:

有人能帮忙编码吗,因为总金额值是通过减法乘法获得的,因为折扣等原因,而不是像我看到的其他来源那样简单地定义为$row['totalamt']

发票


您是否尝试过使用像total_amount这样的变量,并在for循环之前声明它,只需在其中添加数量并在循环之后显示它

    <body>


<?php
if (isset($_POST['submit'])) {

$name_array = $_POST['name'];
$quantity_array = $_POST['quantity'];
$amount_array = $_POST['amount'];
$discount_array= $_POST['discount'];
$total_amount=0;
for ($i =0; $i < count($name_array); $i++) {

$name = $name_array[$i];
$quantity = $quantity_array[$i];
$amount = $amount_array[$i];
$discount = $discount_array[$i];


     echo "<table border='1'>\n"; 
echo "<tr>\n"; 
echo "<th>Description</th>\n"; 
echo "<th>Quantity</th>\n"; 
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Totalamt</th>\n";
echo "</tr>"; 

echo "<tr>"; 
echo "<td>" . $name . "</td>"; 
echo "<td>" . $quantity . "</td>";
echo "<td>" ."$" . $amount . "</td>"; 
echo "<td>"  . $discount . "%" . "</td>"; 
echo "<td>" . "$" .  ($amount - ($amount * ($discount/ 100))) * $quantity . "</td>";
$total_amount+=($amount - ($amount * ($discount/ 100))) * $quantity;
echo "</tr>";

}
echo "total: ".$total_amount;
}

?>




</body>
</html>`

你在问如何做基本的数学运算?好的,如果不使用SQL,是否可以将特定列中的值设置为要“echo”的单个变量?
    <body>


<?php
if (isset($_POST['submit'])) {

$name_array = $_POST['name'];
$quantity_array = $_POST['quantity'];
$amount_array = $_POST['amount'];
$discount_array= $_POST['discount'];
$total_amount=0;
for ($i =0; $i < count($name_array); $i++) {

$name = $name_array[$i];
$quantity = $quantity_array[$i];
$amount = $amount_array[$i];
$discount = $discount_array[$i];


     echo "<table border='1'>\n"; 
echo "<tr>\n"; 
echo "<th>Description</th>\n"; 
echo "<th>Quantity</th>\n"; 
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Totalamt</th>\n";
echo "</tr>"; 

echo "<tr>"; 
echo "<td>" . $name . "</td>"; 
echo "<td>" . $quantity . "</td>";
echo "<td>" ."$" . $amount . "</td>"; 
echo "<td>"  . $discount . "%" . "</td>"; 
echo "<td>" . "$" .  ($amount - ($amount * ($discount/ 100))) * $quantity . "</td>";
$total_amount+=($amount - ($amount * ($discount/ 100))) * $quantity;
echo "</tr>";

}
echo "total: ".$total_amount;
}

?>




</body>
</html>`