pmg200
pmg200

Reputation: 1

Cant get dropbox populated with MYSQL database items

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

Answers (4)

Shanu k k
Shanu k k

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

Manthan Dave
Manthan Dave

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

Prashant Valanda
Prashant Valanda

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

Gayan
Gayan

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

Related Questions