首页 > 解决方案 > How to set selected value in html dropdown if name is array using codeigniter?

问题描述

<h3 class="border_heading"> Academic Details</h3>
<label class="col-sm-2 control-label">10th Class <span class="red-color">*</span></label>
<select class='form-control' name='year[]' id='year' value='' required>
    <option value=''>Year</option>
    <?php
        for($i=2020;$i>=1970;$i--){ 
            echo "<option value='$i' ".set_select('year[]',$i, ( !empty($data) && $data == $i ? TRUE : FALSE )).">$i</option>";
        }
    ?>
</select>

<label class="col-sm-2 control-label">12th Class <span class="red-color">*</span></label>
<select class='form-control' name='year[]' id='year' value='' required>
    <option value=''>Year</option>
    <?php
        for($j=2020;$j>=1970;$j--){ 
            echo "<option value='$j' ".set_select('year[]',$j, ( !empty($data) && $data == $j ? TRUE : FALSE )).">$j</option>";
        }
    ?>
</select>

In the above code I am trying to set value of dropdown. Now, What happen when I select different value of both dropdown then click on submit button then first dropdown show second dropdown value. So, How can I set different value using set_select function? Please help me.

Thank You

标签: phphtmlcodeigniter

解决方案


推荐阅读