我已经尝试了很长时间来填充这个下拉列表,它只显示不在下拉列表中的项目。有什么想法吗?:)
<?php
$html='';
$html.='<select>';
$queryExercise="SELECT exerciseName FROM workouts";
$queryExercise=mysql_query($queryExercise);
while($result=mysql_fetch_array($queryExercise))
{
$exerciseName=$result['exerciseName'];
echo '<option value="'.$exerciseName.'">'.$exerciseName.'</option>';
}
$html.='</select>';
echo $html;
?>发布于 2016-11-21 13:34:56
您的查询运行完美的,但问题是连接生成的下拉 html。
在连接$html中的所有内容时,您需要再次将下拉菜单的结果连接到$html,然后连接到echo $html
在代码下面尝试:
<?php
$html ='<select>';
$queryExercise="SELECT exerciseName FROM workouts";
$queryExercise=mysql_query($queryExercise);
while($result=mysql_fetch_array($queryExercise))
{
$exerciseName=$result['exerciseName'];
$html .= '<option value="'.$exerciseName.'">'.$exerciseName.'</option>';
}
$html.='</select>';
echo $html;
?>发布于 2016-11-21 13:32:25
试试这个,你错过了连接
'<option value="'.$exerciseName.'">'.$exerciseName.'</option>'部分。
<?php
$html ='<select>';
$queryExercise="SELECT exerciseName FROM workouts";
$queryExercise=mysql_query($queryExercise);
while($result=mysql_fetch_array($queryExercise))
{
$exerciseName=$result['exerciseName'];
$html .= '<option value="'.$exerciseName.'">'.$exerciseName.'</option>';
}
$html.='</select>';
echo $html;
?>发布于 2016-11-21 13:32:27
使用以下代码:
<?php
$html='';
$html.='<select>';
$queryExercise="SELECT exerciseName FROM workouts";
$queryExercise=mysql_query($queryExercise);
while($result=mysql_fetch_array($queryExercise))
{
$exerciseName=$result['exerciseName'];
$html.= '<option value="'.$exerciseName.'">'.$exerciseName.'</option>';
}
$html.='</select>';
echo $html;
?>https://stackoverflow.com/questions/40713321
复制相似问题