2014-11-05 79 views
0

这个..如何从数据库中获取值以显示在下拉列表中?

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这个..

<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> 

我怎样才能让这第一部分,使值在一个下拉列表?

回答

0

这会让你想要什么:

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> 

在接下来的页面,与

$_POST['departmentName']; 
+0

获取你的数据我已经全部其他位,我只需要知道我需要做的到这一行echo“”;“,为了使它成为一个下拉列表。 – user3342038 2014-11-05 22:53:58

+0

哪一个? ---- – baao 2014-11-05 22:54:34

+0

“; – user3342038 2014-11-05 22:55:37

相关问题