简体   繁体   English

如何在PHP的列表框中保持价值?

[英]how to keep value in a listbox in PHP?

I got a listbox in my php page that generate from another listbox, the code is as follows 我在我的php页面中有一个从另一个列表框生成的列表框,代码如下

<?php $myArray1 = $_POST['countryRF'];?>
                    <select name='countryRF[]' id='countryRF' size='10' multiple style='width:180px' class='selfont'>
                    <?php
                    foreach($myArray1 as $value){ // Loop through each element
                          print "<option value=\"".$value."\">".$value."</option>";
                    }
                    ?>
                    </option></select>

While refreshing the form listbox get empty, how can I keep added values even after form reload ? 刷新表单列表框时,如果表单重新加载,我怎么能保持添加值?

Is it possible to keep the mysql result table stable even after form reloading by session ? 即使在通过会话重新加载表单之后,是否可以保持mysql结果表稳定? If so please give me a help ? 如果是的话请给我一个帮助?

将它们保存到Sessions中

i see you get the 'countryRF' from post. 我看到你从帖子中获得'countryRF'。

you can store it in a cookie/session, of store it on the server. 您可以将其存储在cookie /会话中,将其存储在服务器上。

use 采用

if (isset($_POST['countryRF'])) {
    $_COOKIE['countryRF'] = $_POST['countryRF'];
}
$myArray = $_COOKIE['countryRF'];

same goes with session 会话也一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM