php - if else statement not work in option input -
here code :
var $myarray =array ('black','blue','brown','yellow') if ( $row['color']=="") { echo"<option value='' selected>---select---</option>"; } foreach ($myarray $color) { if ($row['color']!="" && $row['color']==$color) { echo"<option value='$color' selected>$color</option>"; }else { echo"<option value='$color'>$color</option>"; } }
my question is how rid of (<option value='' selected>---select---</option>)
if $row['color'] not null or not empty?
i´ve tried many ways...but nothing helped. :s
<?php $myarray =array ('black','blue','brown','yellow'); $row['color']=''; ?> <select name='whatever'> <?php if ($row['color']=='' || $row['color']==null){ echo "<option value=''>----select----</option>"; } foreach ($myarray $color){ if ($row['color']==$color){ echo"<option value='$color' selected>$color</option>"; } else{ echo"<option value='$color'>$color</option>"; } } ?>
Comments
Post a Comment