【问题标题】:I want make html option checked with condition from mysql data我想用 mysql 数据中的条件检查 html 选项
【发布时间】:2018-06-23 14:11:47
【问题描述】:

那么如何在 echo php 中创建条件,我有代码 scanario 是,数据将被编辑,ind 选项将输出在数据库中检查的值

<select required="" class="form-control select2_category" name="dokter">
   <option>Pilih Dokter....</option>
     <?php foreach ($dokter as $r) {
        echo "<option value='$r->dokter_name'>$r->dokter_name</option>";
       }
    ?>

【问题讨论】:

  • 请在查询中添加您的 php 代码并显示您尝试过的内容
  • 在什么基础上您要检查选定的选项意味着在什么条件下应该选择它

标签: php arrays codeigniter if-statement foreach


【解决方案1】:

检查一下

<select required="" class="form-control select2_category" name="dokter">
   <option>Pilih Dokter....</option>
     <?php foreach ($dokter as $r) {

        $selected = '';
        if($r->dokter_name == 'data that comming from table' )
          $selected = 'selected';
        else
          $selected = '';

        echo "<option $selected value='$r->dokter_name'>$r->dokter_name</option>";
       }
    ?>

【讨论】:

    猜你喜欢
    • 2017-12-21
    • 1970-01-01
    • 2017-10-08
    • 2011-10-01
    • 2014-04-16
    • 2013-08-08
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    相关资源
    最近更新 更多