我只是个新手。有人可以帮助我迭代或循环我的计算输出从我的表中的所有文本输入。输出仅显示在一行中,不显示在表的另一行中。帮助我解决这个问题更受欢迎。
<head>
<script language="javascript" type="text/javascript">
function calculateSellingPrice()
{
var txtcost = document.getElementById("cost");
var txtsellingprice = document.getElementById("sellingprice");
var txtprofit = document.getElementById("profit");
//find the total first
var total = parseFloat(txtcost.value) + parseFloat(txtpostage.value);
//for selling price computation
txtsellingprice.value = total;
//for ebay fees computation
if (txtsellingprice.value > 50){
txtebayfees.value = parseFloat(txtsellingprice.value - 50) * 0.05 + 3.5;
}
else if (txtsellingprice.value <= 50){
txtebayfees.value = parseFloat(txtsellingprice.value) * 0.07;
}
}
//-->
</script>
</head>
<body onload="calculateSellingPrice();">
<table>
<tr>
<td><center>SKU</center></td>
<td><center>Selling Price</center></td>
<td><center>Cost</center></td>
</tr>
<?php
$result = mysql_query("SELECT sku, sellingprice FROM tbl_inventory");
while ($myrow = mysql_fetch_row($result))
{
?>
<tr>
<td>
<?php echo "<input type='text' id='sku' name='sku' />"; ?>
</td>
<td>
<?php echo "<input type='text' id='sellingprice' name='sellingprice' />"; ?>
</td>
<td>
<?php echo "<input type='text' id='cost' name='cost' />"; ?>
</td>
</tr>
<?php>
}
?>
</table>
答案 0 :(得分:0)
只是指出一些问题,你正在查询你的表,你需要根据返回的值来计算,对吧?
也许你需要一个值来计算某些东西..请看下面我是怎么做的..
<?php echo "<input type='text' id='sellingprice' name='sellingprice' value='".$myrow['sellingprice']."' />"; ?>
你错过了这部分 - &gt; value='".$myrow['sellingprice']."'
答案 1 :(得分:0)
首先:请不要写螺栓。
第二:如果你需要一个表,请使用jQuery Plugin Datatables.net。太棒了!
只需在PHP中创建一个如下所示的数字数组:
$x = array(0 => array(
0 => 'this is a name',
1 => 'this is a price',
2 => 'this is a x')
0 => array(
0 => 'this is a name',
1 => 'this is a price',
2 => 'this is a x')
);
然后执行json_encode(array('aaDara => $x));
并将其用作AjaxSource。真的很棒!