我已经创建了一个表,并且正在从mySQL数据库中提取数据。我已经创建了3列,并希望采用第3列(建议数量)并将这些值复制到第4列(订购数量)的一行文本框中,以便用户可以对其进行编辑。我该怎么做?
$sql = "SELECT item_price.item_id, item_price.ITEM_NAME,suggested_qty,Price_item
FROM item_price JOIN suggested_item
ON item_price.ITEM_NAME = suggested_item.ITEM_NAME";
$result = $conn->query($sql);
?>
<tr>
<th> ID</th>
<th>Item Name</th>
<th>Suggested Quantity</th>
<th>Order Quantity</th>
<th>Total Cost ($)</th>
</tr>
<?php
while ($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $row['item_id'] ."</td>";
echo "<td>" . $row['ITEM_NAME'] . "</td>";
echo "<td>" . $row['suggested_qty'] . "</td>";
}
?>
</table>
答案 0 :(得分:2)
您应该首先将表格包装成表格,然后在带有输入文本字段的列中添加建议的数量。这样的事情应该会让您入门:
$sql = "SELECT item_price.item_id, item_price.ITEM_NAME,suggested_qty,Price_item
FROM item_price JOIN suggested_item
ON item_price.ITEM_NAME = suggested_item.ITEM_NAME";
$result = $conn->query($sql);
?>
<form action="#" method="post">
<table>
<tr>
<th> ID</th>
<th>Item Name</th>
<th>Suggested Quantity</th>
<th>Order Quantity</th>
<th>Total Cost ($)</th>
</tr>
<?php
while ($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $row['item_id'] ."</td>";
echo "<td>" . $row['ITEM_NAME'] . "</td>";
echo "<td>" . $row['suggested_qty'] . "</td>";
echo "<td><input type='text' name='editedvalues[]' value='" . $row['suggested_qty'] . "' /></td>";
echo "<td>total</td>";
echo "</tr>";
}
?>
</table>
</form>
您应该在输入字段中添加一个javascript onchange侦听器,以计算每一行的总价并将其显示给用户。