Display Dropdown in HTML with PHP

2019-06-08 06:12发布

问题:

I am android developer and making one admin panel for one of my android application. I know very basic PHP. currently I am displaying input field with value and user can change with text input and can save value with submit button. Its like below

<div class="form-group">
  <label class="col-md-3 control-label">Admob On/off :-</label>
  <div class="col-md-6">
    <input type="text" name="ads_status" id="ads_status" value="<?php echo $settings_row['ads_status'];?>" class="form-control">
  </div>
</div>

Instead of input value I want show dropdown menu with two item called on and off. When user load page it should show value based on previous save. Like if user have made setting on it must display on. I am displaying value now from database. Let me know if anyone can suggest me what Should I do for it. Thanks

回答1:

<div class="form-group">
  <label class="col-md-3 control-label">Admob On/off :-</label>
  <div class="col-md-6">   
   <select class="form-control " type="text" name="ads_status"  >
     <option value="on" <?php if($settings_row['ads_status']== 'on') echo "selected = 'selected'" ?> >On</option>
     <option value="off" <?php if($settings_row['ads_status'] == 'off') echo "selected = 'selected'" ?> >Off</option>
   </select>
  </div>
</div>

I hope this will hep you.