dousheng3364 2013-12-01 15:07
浏览 14

保持选择来自数据库的选择框值?

i hope you can help i have got this query in a select box who listed all countrys out from database. i checked some solutions from similar questions but its didn't worked for me. how would i do this to keep the selected country selected after page refresh?

<select name="themecat[]" class="ui-widget" id="cb1">
<option value=choose a country>choose a country</option>
 <?php
 include_once("php_includes/db_conx.php");
 $sql = "SELECT countrys FROM countrylist";
 $query = mysqli_query($db_conx, $sql);
while ($row = mysqli_fetch_array($query))
{
echo "<option value='{$row['countrys']}'>{$row['countrys']}</option>";
}
?>
</select>
  • 写回答

1条回答 默认 最新

  • dozug64282 2013-12-01 15:18
    关注

    This depends on what you mean by "refresh".

    If you are literally refreshing ie, F5, then you could use Javascript to store the value of the select in a session and on load if the session variable is set, set the select tag to selected.

    If you want to only do it if the page is "POST", you can check in php if the page has been posted by checking the _POST varaible and setting the selected attribute accordingly.

    See here on an example of how to set the selected option in PHP.

    Display stored value from mysql table into select input field

    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等