doutang9037 2019-07-14 14:42 采纳率: 100%
浏览 80
已采纳

如何在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 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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问各位,如何在Jetson nano主控板的Ubuntu系统中安装PyQt5
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥150 求 《小魔指》街机游戏机整合模拟软件