phpcodeigniterdropdownselected

dropdown selected update in codeigniter


The dropdown can't show selected item in form update. But the code has the same as other dropdown

  1. The code below can show the selected item on dropdown
  <div class="col-md-3 pl-pr-1">
     <div class="form-group">
         <label>Dry Process</label>
         <?php $dry = $u->dry; ?>
         <select name="dry" id="dry" class="form-control" required> 
         <option selected disabled>Pilih</option>
         <option <?php echo ($dry == 'Line Dry/Flat Dry') ? "selected": "" ?>>Line Dry/Flat Dry</option>
         <option <?php echo ($dry == 'Tumble Dry') ? "selected": "" ?>>Tumble Dry</option>
         <option <?php echo ($dry == 'All') ? "selected": "" ?>>All</option>
         <option <?php echo ($dry == 'None') ? "selected": "" ?>>None</option>
         </select>
     </div>
 </div>
  1. The code below can't show the selected item on dropdown
 <div class="col-md-3 pl-pr-1">
    <div class="form-group">
        <label>Technology Concept</label>
        <?php $technology_concept = $u->technology_concept; ?>
        <select name="technology_concept" class="form-control" required>
            <option selected disabled>PILIH</option>
            <option <?php echo ($technology_concept == 'TECHFIT') ? "selected": "" ?>>TECHFT</option>
            <option <?php echo ($technology_concept == 'TECHFIT RECHARGER') ? "selected": "" ?>>TECHFIT RECHARGER</option>
            <option <?php echo ($technology_concept == 'CONTROL') ? "selected": "" ?>>CONTROL</option>
            <option <?php echo ($technology_concept == 'FORMOTION') ? "selected": "" ?>>FORMOTION</option>
            <option <?php echo ($technology_concept == 'none') ? "selected": "" ?>>none</option>
        </select>
    </div>
</div>

The first dropdown is point 1 and The second dropdown is point 2

I've tried nothing in code just recheck with the code before for make sure the code has same with other code. But it still can't selected the dropdown item on update.


Solution

  • Your code looks good to me except one typo in following line.

    <option <?php echo ($technology_concept == 'TECHFIT') ? "selected": "" ?>>TECHFT</option>
    

    Here, value of option is "TECHFT" and you are comparison value is "TECHFIT".