如何在PHP中从数据库填充的表中捕获动态输入
标题说明了一切,我想在制作订单时捕获表中的输入字段。通过选择选项Supplier从数据库填充车身数据 感谢所有的帮助。多谢各位如何在PHP中从数据库填充的表中捕获动态输入,php,html,mysql,Php,Html,Mysql,标题说明了一切,我想在制作订单时捕获表中的输入字段。通过选择选项Supplier从数据库填充车身数据 感谢所有的帮助。多谢各位 <form method="post"> <select name="supplier" required> <option disabled selected value> -- Select an option -- </option> <?php while($rowname =
<form method="post">
<select name="supplier" required>
<option disabled selected value> -- Select an option -- </option>
<?php
while($rowname = mysqli_fetch_array($allsup2))
{
echo '<option value="'.$rowname['sup'].'">'.$rowname['sup'].'</option>';
}
?>
</select>
<input type="submit" name="submit" value="Go" />
</form>
<table id="resultTable" style="position: relative;" class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th width="60%" class="small">Name</th>
<th width="40%" class="small">Quantity</th>
</tr>
</thead>
<tbody>
<?php
if(isset($_POST['submit']))
{
$supplier = $_POST['supplier'];
$query = "SELECT * FROM supplies where supplier='$supplier'";
$result = mysqli_query($con, $query);
while($results = mysqli_fetch_array($result))
{
$result_array[] = $results;
}
echo '<form method="post">';
foreach ($result_array as $result)
{
echo '<tr>';
echo '<td class="small">'.$result['product'].'</td>';
echo '<td class="small"><input type="text" name="'.$result['id'].'"/></td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
<input type="submit" name="submit2" value="Order now" class="right s-12 btn btn-default" />
</form>
<?php
if(isset($_post['submit2']))
{
//capturing input field to put in the order cart
}
?>
与其将$result['id']用作名称值,不如将其用作数组键,即name=dynamic['.$result['id'.]。然后在php中,您可以使用foreach->foreach$\u POST['dynamic']作为$key=>$value{…}循环这些函数。谢谢您的回答。但是,如果我使用foreach$\u POST['dynamic']作为$key=>$value,我如何从数据库中调用产品名称?我能用这个吗$将$\u POST['dynamic']、$result\u数组组合为$result=>$key?与其将$result['id']用作名称值,不如将其用作数组键,即name=dynamic['.$result['id'.]。然后在php中,您可以使用foreach->foreach$\u POST['dynamic']作为$key=>$value{…}循环这些函数。谢谢您的回答。但是,如果我使用foreach$\u POST['dynamic']作为$key=>$value,我如何从数据库中调用产品名称?我能用这个吗$将$\u POST['dynamic']、$result\u数组组合为$result=>$key?