lundi 6 janvier 2020

Use a default value in combo box in php

I use a dropdown list in php where I need to show the default value as Australia. I use below code. But it gives me an error by saying I use if statement in a wrong place.

Please help me to resolve this. Thank you very much

<div class="col-sm-offset-2 col-xs-9">
  <select class="select2" name="country" id="country" data-placeholder="Country" required style="width:100%;">
    <option value=""> Select </option>
    <?php foreach($this->countries as $pro){
      echo '<option value="'.$pro->id.'" '.if($pro->country_name == "Australia"){.'selected'.}.'>'.$pro->country_name.'</option>'; 
    }
?>
  </select>
</div>

Aucun commentaire:

Enregistrer un commentaire