php: nested if in select tag
nested if needs to be grouped to avoid unexpected error:
Ex:
//
//Parse error: parse error, unexpected ':'
$slect='<option value="1" '.$val== "1" ? 'selected="selected"' :''.'>slect1</option>';
//Work:
$slect='<option value="1" '.($val == "1" ? 'selected="selected"' :'').'>slect1</option>';
echo $var;
Ex:
//
//Parse error: parse error, unexpected ':'
$slect='<option value="1" '.$val== "1" ? 'selected="selected"' :''.'>slect1</option>';
//Work:
$slect='<option value="1" '.($val == "1" ? 'selected="selected"' :'').'>slect1</option>';
echo $var;
Comments
Post a Comment