我想添加一個計算字段,其中用戶輸入訂單數量的數字並顯示該產品的總成本如何從用戶輸入和SQL數據庫創建計算字段
我對的產品列表中的表,然後從我的SQL數據庫
if ($num_results1 > 0) {
echo "<table><tr><th>Row Number</th><th>Name</th><th>Quantity</th><th>Weight</th><th>Price</th><th>Total</th></tr>";
for ($i=0; $i <$num_results1; $i++)
{
$row = mysqli_fetch_assoc($result1);
echo
"<tr>".
"<td class = 'row-number'>". $i ."</td>".
"<td class = 'Product-Name'>". $row["Cheese"]."</td>".
"<td class = 'Quantity'>" .'<input type="number" name="Box" id="text" />'. "</td>".
"<td class = 'Weight'>" . $row["Size(in Kg)"] ."kg". "</td>".
"<td class = 'Cost'>" ."€ ". $row["SellingPrice(Euro)"]. "</td>".
"<td class = 'total'>".'calculate('.$row["SellingPrice(Euro)"].')'."</input></td>".
"</tr>";
calculate()
是一個JavaScript函數我寫的客戶希望訂購量,以獲得產品的成本有詳細介紹
<script>
function getQuantity(i)
{
//reference to the form
var theForm =document.forms["customerOrder"];
//referenece to the element
var quantity = theForm.elements["Box"];
var howmany=0;
if(quantity[i].value!="")
{
howmany=parseInt(quantity[i].value);
}
return howmany;
}
function calculate(k)
{
var calc= '.$row["SellingPrice(Euro)"].' * getQuantity(k);
return calc;
}
</script>
getQuantity()試圖提取客戶在網頁中輸入的值。
我已經打過電話,在PHP代碼回聲的腳本,我的問題我認爲是試圖獲得數量
所以在最後我希望創建一個函數來計算總成本和顯示器的引用,在我最後一欄,它需要是動態的,以適應我的SQL數據庫作爲銷售產品的數量變化,謝謝
那是什麼''在過去? – pmirnd