How to Keep the selected value of the select box after Form POST or GET

前端 未结 8 1940
無奈伤痛
無奈伤痛 2021-01-03 15:33

Im trying to implement the search feature in my website.

when the search keyword is entered in the textbox, and the category combo is selected, the form will be Pos

8条回答
  •  迷失自我
    2021-01-03 15:40

    $countries_uid = $_POST['countries_uid'];
                    while($row = mysql_fetch_array($result)){
                      $uid = $row['uid'];
                      $country = $row['country_name'];
                      $isSelected = null;
                        if(!empty($countries_uid)){
                        foreach($countries_uid as $country_uid){//cycle through country_uid
                           if($row['uid'] == $country_uid){
                            $isSelected = 'selected="selected"'; // if the option submited in form is as same as this row we add the selected
                           }
                        }
                       }else {
                        $isSelected = ''; // else we remove any tag
                      }
                      echo "";
                    }
    

    this is my solutions of multiple select dropdown box after modifying Mihai Iorga codes

提交回复
热议问题