gpt4 book ai didi

php - 在选择框中保留所选值

转载 作者:太空宇宙 更新时间:2023-11-03 11:32:41 25 4
gpt4 key购买 nike

如何在从数据库动态填充的选择框中保留我选择的选项。我看过很多答案,但大多数都是针对静态值的。这是我的代码,

  <select name="batchnumber" class="form-control"  id="batchno" required>   

<option value="">select batch number</option>
<?php
$sql = mysql_query("SELECT DISTINCT rpp_regn_bulkbatch_no,rpp_id FROM tbl_regn_prescribed_parameters where rpp_regn_bulkbatch_no != 0");
while ($row = mysql_fetch_assoc($sql)){

echo "<option value=" . $row['rpp_regn_bulkbatch_no'] . ">" . $row['rpp_regn_bulkbatch_no'] . "</option>";
}
?>
</select>

最佳答案

你好,我们可以简单地通过添加 if 条件来做到这一点,

while ($row = mysql_fetch_assoc($sql))
{
if($_REQUEST['batchnumber'] == $row['rpp_regn_bulkbatch_no'])
{
echo "<option selected value=" . $row['rpp_regn_bulkbatch_no'] . ">" . $row['rpp_regn_bulkbatch_no'] . "</option>";
}
else
{
echo "<option value=" . $row['rpp_regn_bulkbatch_no'] . ">" . $row['rpp_regn_bulkbatch_no'] . "</option>";
}

}

但尝试使用 mysqli_* 函数而不是 mysql_*

关于php - 在选择框中保留所选值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48500440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com