[英]how to put an input box next to each item in a database using php
I am currently learning PHP and HTML so please bear with me. 我目前正在学习PHP和HTML,请耐心等待。
I have a web page that shows a table, the content of this table is from a database on the localhost which constantly gets updated (this displays our stock on hand in our warehouse). 我有一个显示表格的网页,该表格的内容来自本地主机上的数据库,该数据库会不断更新(这将显示我们仓库中的现有库存)。 The table has 3 columns - Item Number - Description - Quantity Available.
该表有3列-项目编号-说明-可用数量。
What I am trying to do is get input boxes next to each item so that the user can type in a quantity they would like to order. 我正在尝试做的是在每个项目旁边获取输入框,以便用户可以输入他们想订购的数量。
I'm having trouble with seeing how I can do this. 我在查看如何执行此操作时遇到了麻烦。 My understanding is along the lines of -> 'for each item in this item number field, create an input box' but I found that I can't run a query for the list of items and create a form\\input box at the same time (if this makes sense).
我的理解是->'为此项目编号字段中的每个项目创建一个输入框',但是我发现我无法对项目列表进行查询并在同一位置创建一个表格\\输入框时间(如果有意义)。 So I am back to square one where all I have is a list of item numbers and no idea where to go next.
所以我回到第一个方框,那里只有物品编号列表,不知道下一步去哪里。
(Note: In the past there has been confusion about how they user is going to pay for the order - there is no payment facilities being implemented in this - this is just about creating input boxes for a dynamically changing database.) (注意:过去,用户如何为订单付款一直很混乱-没有实现付款功能-这只是为动态更改的数据库创建输入框。)
Thank you, Matt 谢谢你,马特
As requested - current code (apologies if I pasted it in wrong): 根据要求-当前代码(如果我粘贴错了,我们深表歉意):
<?php
echo "<div id=header>";
echo "<h1>Stock on hand listing</h1>";
echo "<p>Stock is updated every hour during business hours</p>";
echo "</div>";
echo "<br />";
echo "<link rel='stylesheet' href='table.css' type='text/css'>";
$conn = mysql_connect('localhost', '*****', '*****');
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('****_SOH',$conn);
/* select only items with stock on hand */
$result = mysql_query("SELECT * FROM TABLE_SOH where (((TABLE_SOH.ITM_ONHAND) >0))",$conn);
echo "<table border='0'>
<tr>
<th>Item</th>
<th>Description</th>
<th>On Hand</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ITM_NO'] . "</td>";
echo "<td>" . $row['ITM_DES'] . "</td>";
echo "<td align=right>" . $row['ITM_ONHAND'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($conn);
?>
Assuming that you have already made a sql query to get the columns -item and description , you need to insert a php code in the sql query block like 假设您已经进行了sql查询以获取-item和description列,则需要在sql query块中插入php代码,例如
<?php
echo ("<input type ='text' name ='item'.$i >");
?>
That should append a text column in every row of the table. 那应该在表的每一行中添加一个文本列。 $i corresponds to each item and will help you retrieve data stored in each row.
$ i对应于每个项目,将帮助您检索存储在每一行中的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.