我有一个名字和姓氏的MySQL数据库,我可以使用它填充下拉列表。但我想要一个下降。我也设法做到这一点。但是当我提交这些信息时,我被困住了,然后两个项目(第一个和第二个姓氏)被重新发回到我的数据库。PHP从两个mysql列下拉菜单
这是我迄今为止
<table align="center">
<form name="addreport" action="addreport.php" method="post">
<?php
$options = '';
$filter=mysql_query("select * from students");
while($row = mysql_fetch_array($filter)) {
$options .="<option value = '".$row['firstname']."'>" . $row['firstname'] . " " .$row['surname']."'>" . $row['surname'] . "</option>";
}
$menu="<name='filter'>
<select name='names'>
" . $options . "
</select></td>";
?>
<tr><td><font color='white' size='6px'>Student Name:<?php echo $menu; ?></td></tr>
<tr><td><font color='white' size='6px'>Teacher Name:<input type="text" name="location" size="12"/></td></tr>
<tr><td><font color='white' size='6px'>Report:</td>
<tr><td><textarea name="report" style="font-size:15px;width:800px;height:300px;"></textarea></td></tr>
<tr><td><font color='white' size='6px'>Intervention:</td></tr>
<tr><td><textarea name="interv" style="font-size:15px;width:800px;height:300px;"></textarea></td></tr>
</table>
<table align="center">
<tr><td><center><input type="submit" class="btn2" value="Add"></center></td></tr>
</form>
</table>
</body>
</html>
棍子在我的形式发送信息上回我的数据库。正如你所看到的,我可以发回一回,但不能两回。请有人帮我组织这最后一部分。
首先,而不是在PHP中处理,您可以更改您的查询为:'选择id,CONCAT(firstname,',surname)fr om学生'。并且''
'$ options'永远不会被回显。你的问题很不明确,特别是关于你的具体编程问题。你写了很多你已经做的事情,但很少有你的问题,你如何试图解决它,以及为什么这个解决方案不适合你。 – hakre
@hakre选项被回显,因为它与$ menu连接。 – ADyson