dongzha0813 2011-08-30 03:34 采纳率: 0%
浏览 25
已采纳

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

I got a listbox in my php page that generate from another listbox, the code is as follows

<?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 ? If so please give me a help ?

  • 写回答

2条回答 默认 最新

  • doujiu6976 2011-08-30 03:41
    关注

    i see you get the 'countryRF' from post.

    you can store it in a cookie/session, of store it on the server.

    use

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

    same goes with session

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?