duanhe0817825 2018-08-04 04:52 采纳率: 100%
浏览 154
已采纳

如何在多个选择中保留所选值,如bootstrap-select

I want to retain the value that I selected after form submission.

<select name="student[]" class="selectpicker" multiple title="Click here.." data-width="auto" data-live-search="true" required>
  <?php  
    if (isset($_POST['submit'])){
    $selected = $_POST['studname'];
    $qry = "Select studtbl.stud_id,concat(studtbl.fname,' ', 
    substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
        $result = mysqli_query($conn, $qry);
        while($row = mysqli_fetch_array($result))
        {
        extract($row);
        echo '<option value="'.$stud_id.'" '.(($stud_id == 
        $selected)? 'selected="selected"':"" >'.$Name.'</option>';
        } 
    }else{
    $qry = "Select studtbl.stud_id,concat(studtbl.fname,' ', 
    substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
                $result = mysqli_query($conn, $qry);
                while($row = mysqli_fetch_array($result))
                {
                    extract($row);
                    echo '<option value="'.$stud_id.'" >'.$Name.'</option>';
                } 
    }
    ?>
</select>
<input type='submit' class="btn btn-primary" name='submit' value='Create 
     Account' />

My problem is it is not retaining after submitting

</div>
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 这段有什么bug 为什么总报错
      • ¥15 关于#php#根据url判断选择加载模板应该如何解决?会的速来捡钱!
      • ¥15 Intel Realsense深度相机(D415/D435)拍摄梯子获取梯子点云
      • ¥50 unity使用easyar录屏更换视频保存路径
      • ¥15 CECGameSession::OutputLinkSevError(iRetCode=4) LINK超时
      • ¥20 出错 textread (第 124 行) [varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
      • ¥15 tensor flow目标检测环境配置问题
      • ¥15 数据库float型转换精度问题
      • ¥15 运行您代码时出现报错,如何解决?(标签-回归|关键词-无法识别)
      • ¥50 android service弹出dialog,showdialog就出错,如何解决?