0
我有一个表格,用户输入数据。行是动态创建的。用户给出的值被发送到数据库(Oracle 11g),并根据其他值被提取并插入到表中。代码如下:从数据库中获取值并在html表格中显示,包括PHP
<!DOCTYPE HTML>
<html>
<body>
<?php
$code = $_POST['code'];
$qty = $_POST['qty'];
foreach ($_POST['code'] as $code => $c) {
//print $c . " " . $qty[$code] . "<br>";
}
$link = oci_connect('hd','hd', 'localhost/mydb');
if(!$link) {
$e = oci_error();
exit('Connection error ' . $e['message']);
}
foreach ($_POST['code'] as $code => $c)
{
$q1 = "select PROD_NAME, PROD_COST from PRODUCT where PROD_ALIAS = :bv_code";
$q1parse = oci_parse($link, $q1);
oci_bind_by_name($q1parse, ':bv_code', $c);
oci_execute($q1parse);
while($row = oci_fetch_array($q1parse))
PRINT $row['PROD_NAME'] . " " . $row['PROD_COST'] .
" " . $qty[$code] . " " .
($row['PROD_COST']*$qty[$code]) . "<br>";
}
?>
<script type = "text/javascript" >
function addRow()
{
var table = document.getElementById('order');
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
cell1.innerHTML = "<input type = 'text' name = 'code[]' /> ";
cell2.innerHTML = "";
cell3.innerHTML = "";
cell4.innerHTML = "<input type = 'text' name = 'qty[]' />";
cell5.innerHTML = "";
}
function delRow(r)
{
document.getElementById('order').deleteRow(-1);
}
</script>
<p><strong> Order Details </strong></p>
<form action = 'm3.php' method = 'POST' >
<table id = "order" border = 1 border_collapse = "collapse" >
<tr>
<th> Item Code </th>
<th> Name </th>
<th> Price </th>
<th> Quantity </th>
<th> Total </th>
</tr>
</table>
<input type = 'submit' name = 'submit' value = 'Submit' />
<input colspan = '2' type = "button" value = "Add Row" onclick = "addRow('order')" />
<input colspan = '2' type = "button" value = "Delete Row" onclick = "delRow('order')" />
</form>
</body>
</html>
用户提供“CODE”和“Quantity”的值。 “代码”被发送到数据库并获取产品的其他值。问题是我想在同一个表中显示提取的值。现在我在桌子外面显示它。另外,我想在最后一栏显示总账单。如在,总价(价格*数量)。我怎样才能做到这一点?
哦这是伟大的。它的工作原理,但如何做到这一点?如在总金额? –
@KaranGupta我已经更新了我的回答,以解决您的意见,即容纳总金额计算。希望这会解决你的问题。 –
它没有给出想要的结果。我得到一个错误“第70行的未定义变量sumTotal”,即我们声明'sumTotal'的那一行。但是它也显示了结果,虽然在表 –