使用" echo"将字符串分配给变量失败时

时间:2016-04-30 03:22:07

标签: php html drop-down-menu

我正在尝试编写一个PHP脚本,该脚本从数据库获取值并将其设置为名为gender的下拉列表。我写了以下代码:

  while($row = mysqli_fetch_assoc($result))
        { 
    $gender = $row['gender'];
    $output.= "Gender: <select name='gender'>   
<option value='0' ".if ($gender != 'M' || $gender !='F') { echo ('selected="selected"');}.">Select gender</option> 
<option value='M' ". if ($gender == 'M') { echo ('selected="selected"');}.">Male</option>  
<option value='F' ". if ($gender == 'F') { echo ('selected="selected"');}.">Female</option></select>";
    }

由于echo语句(echo ('selected="selected"')):

,我收到服务器错误
The website encountered an error while retrieving http://localhost/search.php. It may be down for maintenance or configured incorrectly.

这是什么解决方案?

2 个答案:

答案 0 :(得分:1)

你可以做一个简单的比较函数,通过比较两个参数来返回选择字符串:

df = pd.read_csv('Sample.csv',index_col='date')
df2 = df.groupby(['wholesaler','product'])['sales'].apply(pd.expanding_mean)

答案 1 :(得分:0)

好的,这里最好的选择就是删除问题的根源,将其作为if语句:

if ($gender != 'M' && $gender != 'F') {
    output .= "...Enter he html with he generic answer selected...";
}
else if ($gender == 'M') {
    output .= "...Enter html with Male selected...";
else {
    output .= "...Enter html with Female selected...";
}

它可能有点笨重,但它可以完成这项任务。