doutang9037
doutang9037
采纳率100%
2019-07-14 14:42 阅读 76
已采纳

如何在codeigniter中使用控制器中所选选项的select标签?

I am using Codeigniter. In the controller, I have a select tag something like

  $action='<select name="pp_fileStatus[]" class="form-control multipleselect wip_fileStatus" data-id="'.$row->bank_id.'">
           <option value="" disabled selected>File Status</option>
           <option value="1">Disbursed </option>
           <option value="2">Files sumitted </option>
           <option value="3">Pendency </option>
           <option value="4">Approved</option>
           <option value="5">Rejected</option>
           <option value="6">Dropped</option>
           </select>';

Now what I am doing is, I have to use an if condition to show the selected option. So I tried:

<option value="1"'if($row->status == "1"){ echo "selected"; }'>Disbursed </option>

but it is showing the wrong results.

Should I create something like this:

$action='<select name="pp_fileStatus[]" class="form-control multipleselect wip_fileStatus" data-id="'.$row->bank_id.'">
<option value="" disabled selected>File Status</option>
<option value="1"';
 if($row->b_filestatus == "1"){ echo "selected"; }
 $action='>Disbursed </option>
 <!--more here-->

or should I use an altogether different method?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongliping003116 dongliping003116 2019-07-14 17:06

    You can try like this

    $action='<select name="pp_fileStatus[]" class="form-control multipleselect wip_fileStatus" data-id="'.$row->bank_id.'">
               <option value="" disabled selected>File Status</option>
               <option value="1"'. ($row->status == "1"?'selected':'').' >Disbursed </option>
               <option value="2"'. ($row->status == "2"?'selected':'').'>Files sumitted </option>
               <option value="3"'. ($row->status == "3"?'selected':'').'>Pendency </option>
               <option value="4"'. ($row->status == "4"?'selected':'').'>Approved</option>
               <option value="5"'. ($row->status == "5"?'selected':'').'>Rejected</option>
               <option value="6"'. ($row->status == "6"?'selected':'').'>Dropped</option>
               </select>';
    
    点赞 评论 复制链接分享

相关推荐