Reputation: 1
I have been trying for ages to get this dropdown populated and it displays the items just not inside the dropdown. Any ideas? :)
<?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;
?>
Upvotes: 0
Views: 50
Reputation: 1285
This code also working fine
<?php
echo '<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>';
}
echo '</select>';
?>
Upvotes: 0
Reputation: 2147
Your Query works perfect but issue is concat the generated dropdown html.
As you are concating everything in $html so again you need to concate the result of dropdown to $html and then echo $html
Try below code :
<?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;
?>
Upvotes: 2
Reputation: 480
use below code:
<?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;
?>
Upvotes: 0
Reputation: 2935
Try this, You missed to concatenate
'<option value="'.$exerciseName.'">'.$exerciseName.'</option>'
section.
<?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;
?>
Upvotes: 0