如何在Codeignator的控制器中使用带有选择选项的选择标签?

时间:2019-07-14 14:42:25

标签: php html if-statement codeigniter-3

我正在使用Codeigniter。在控制器中,我有一个选择标签,例如

  $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>';

现在我在做什么,我必须使用if条件来显示所选的选项。所以我尝试了:

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

但是显示错误的结果。

我应该创建这样的东西吗?

$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-->

还是我应该使用完全不同的方法?

1 个答案:

答案 0 :(得分:0)

您可以尝试这样

$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>';