[英]How to get values from a database to show up in a drop down list?
This.. 这个..
while ($line = sqlsrv_fetch_array($query_result, SQLSRV_FETCH_ASSOC)) {
$departmentName = trim($line['Department']);
echo "<input type=\"submit\" value=\"$departmentName\" name=\"departmentName\"/>";
echo "<br>";
yeilds this.. 这样。
<form action="process_case2.php" method="post">
<input type="submit" value="Accounting" name="departmentName"/><br>
<input type="submit" value="Administration" name="departmentName"/><br>
<input type="submit" value="Finance" name="departmentName"/><br>
<input type="submit" value="Human Resources" name="departmentName"/><br>
<input type="submit" value="InfoSystems" name="departmentName"/><br>
<input type="submit" value="Legal" name="departmentName"/><br>
<input type="submit" value="Marketing" name="departmentName"/><br>
<input type="submit" value="Production" name="departmentName"/><br>
</form>
How can I make the first part of this, so that the values are in a drop down list? 我如何才能做到这一点的第一部分,以便这些值在下拉列表中?
This will make what you want: 这将使您想要:
while ($line = sqlsrv_fetch_array($query_result, SQLSRV_FETCH_ASSOC)) {
$departmentName[] = trim($line['Department']);
}
?>
<form action="process_case2.php" method="post">
// paste other fields here
<select id="what" class="ever" name="departmentName">
<?php
foreach ($departmentName as $a)
{
?>
<option value="<?= $a; ?>"><?= $a; ?></option>
<?php
}
?>
</select>
// or here
<input type="submit" name="submit" value="submit"/>
</form>
On the next page, fetch your data with 在下一页上,使用
$_POST['departmentName'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.