我正在努力学习如何编程,这是我的第一个项目。我知道我应该阅读教程,但我有点坚持它。真想自己完成它,但它变得令人沮丧..有人至少可以指导我朝着正确的方向前进吗? 那么,如何根据下拉列表选择将数据回显到表格单元格? 任何帮助非常感谢。 代码到目前为止: http://jsfiddle.net/uFEPn/3/
<select>
<option>-- Select lot --</option>
<?php
mysql_connect('localhost','root','');
mysql_select_db('pl_base');
$query="SELECT DISTINCT lot_number FROM pl_table";
$result=mysql_query($query);
while(list($lot_number)=mysql_fetch_row($result)) {
echo "<option value=\"".$lot_number."\">".$lot_number."</option>";
}
?>
</select>
</br>
<table border="1" id="table">
<tr>
<th width=80 height=30>Lot<br/>number</th>
<th width=110 height=30>Description</th>
<th width=90 height=30>Pallet<br/>number</th>
<th width=60 height=30>Net</th>
<th width=60 height=30>Gross</th>
</tr>
<tr>
<td>#</td>
<td rowspan="5">echo results here</td>
<td><b>Total</b></td>
<td>#</td>
<td>#</td>
</tr>
<td> # </td>
<td colspan="3">#</td>
</tr>
<tr>
<th>&</th>
<th>&</th>
<th>&</th>
<th>&</th>
</tr>
</table>
数据库中的表:
+--------------------------+-------------------------+---------+-------+
| id | lot_number | descr | pallet_number | net | gross |
+--------------------------+-------------------------+---------+-------+
| 1 | 111 | black | 1 | 800 | 900 |
| 2 | 111 | black | 2 | 801 | 901 |
| 3 | 111 | black | 3 | 802 | 902 |
| 4 | 222 | white | 1 | 800 | 900 |
| 5 | 222 | white | 2 | 801 | 901 |
| 6 | 222 | white | 3 | 802 | 902 |
+--------------------------+-------------------------+---------+-------+
答案 0 :(得分:0)
选择元素中的批号不会直接使用php更新。 因为php是服务器端语言,所以你必须将数据作为表单提交然后再显示它。
<?php
mysql_connect('localhost','root','');
mysql_select_db('pl_base');
$query="SELECT DISTINCT lot_number FROM pl_table";
$result=mysql_query($query);
?>
<form action="" method="POST">
<select name="option_chosen">
<option>-- Select lot --</option>
<?php
while(list($lot_number)=mysql_fetch_row($result)) {
echo "<option value=\"".$lot_number."\">".$lot_number."</option>";
}
?>
</select>
<input type="submit" value="Submit" />
</form>
</br>
<table border="1" id="table">
<tr>
<th width=80 height=30>Lot<br/>number</th>
<th width=110 height=30>Description</th>
<th width=90 height=30>Pallet<br/>number</th>
<th width=60 height=30>Net</th>
<th width=60 height=30>Gross</th>
</tr>
<?php
if($_SERVER['REQUEST_METHOD'] =='POST')
{ $option_chosen=$_POST['option_chosen'];
$query="SELECT * FROM pl_table WHERE lot_number='$option_chosen'";
$run=mysqli_query($query);
$row=mysqli_fetch_array($run, MYSQLI_ASSOC);
echo "<tr><td>".$row['lot_number']."</td>";
echo "<td>".$row['descr']."</td><td>".$row['pallet_number']."</td>";
echo "<td>".$row['net']."</td><td>".$['gross']."</td></tr>";
}
?>
</table>