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

PHP表单-突出显示SQL查询的多个选择,php,sql,forms,Php,Sql,Forms,我试图在提交后在下拉列表中选择多个选项,但我无法让它工作。这些选项不会保持选中状态。我已经用foreach()看到了这个问题的答案,但是我的数据来自一个SQL查询,所以我认为我需要使用while()来循环行。有什么想法吗 $id7 = $_REQUEST['id7'];// Interest Level <?php $getParameter_sql4 = 'SELECT Funds.[Interest Level] FROM Funds GROUP BY Funds.[Interest

我试图在提交后在下拉列表中选择多个选项,但我无法让它工作。这些选项不会保持选中状态。我已经用foreach()看到了这个问题的答案,但是我的数据来自一个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>
$id7=$\u请求['id7'];//利息水平

我想这可能与php之外的单引号有关,在传递到查询时,我需要单引号:''。我找到了答案。我必须使用str_replace()删除$id7中的单引号,并在in_数组()中使用它。