PHP表单 - 突出显示SQL查询的多个选择

时间:2014-02-21 20:08:13

标签: php sql forms

我正在尝试在提交后在下拉表单中选择多个选项,但我无法让它工作。选项不会保持选中状态。我已经使用foreach()(Highlighting multiple selections on a form after submitting)看到了这个问题的答案,但是我的数据来自SQL查询,所以我相信我需要使用while()循环遍历行。有什么想法吗?

$id7 = $_REQUEST['id7'];// Interest Level

<?php
$getParameter_sql4 = 'SELECT Funds.[Interest Level] FROM Funds GROUP BY Funds.[Interest Level] ORDER BY Funds.[Interest Level]';
$getParameter4 = sqlsrv_query($conn,$getParameter_sql4);
?>

<form action="/Reports/FundStatistics.php" method="get">

<select name="id7[]" multiple size="4">
<?php while ($row4 = sqlsrv_fetch_array($getParameter4, SQLSRV_FETCH_ASSOC)) { ?>
<option <?php if (in_array($row4['Interest Level'],$id7)) { echo 'selected="selected"';}?> value="'<?php echo $row4['Interest Level']; ?>'"><?php echo $row4['Interest Level']; ?></option><?php }?>
</select>

<input type="submit" VALUE="Update" /></form>

0 个答案:

没有答案