猿问

如何将表中导入的sql值复制到文本框中?

我已经创建了一个表,并且正在从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>


人到中年有点甜
浏览 98回答 1
1回答

慕沐林林

您应该首先将表格包装成表格,然后在带有输入文本字段的列中添加建议的数量。这样的事情应该可以帮助您入门:$sql = "SELECT item_price.item_id, item_price.ITEM_NAME,suggested_qty,Price_itemFROM item_price JOIN suggested_item&nbsp;&nbsp;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><?phpwhile ($row = $result->fetch_assoc())&nbsp;{&nbsp; &nbsp; echo "<tr>";&nbsp; &nbsp; echo "<td>" . $row['item_id'] ."</td>";&nbsp; &nbsp; echo "<td>" . $row['ITEM_NAME'] . "</td>";&nbsp; &nbsp; echo "<td>" . $row['suggested_qty'] . "</td>";&nbsp; &nbsp; echo "<td><input type='text' name='editedvalues[]' value='" . $row['suggested_qty'] . "' /></td>";&nbsp; &nbsp; echo "<td>total</td>";&nbsp; &nbsp; echo "</tr>";}?></table></form>您应该在输入字段中添加一个javascript onchange侦听器,以计算每一行的总价并将其显示给用户。
随时随地看视频慕课网APP
我要回答