0

I'm trying to populate a select element with firstname and lastname values from a MySQL database.

At this point I have the code bringing back the data and inserting only one row into the select element and then displaying the remaining data below the select element.

I'm not sure why this is not inserting all of the data into an option tag - any and all help is appreciated, I read similar questions and could not figure this out.

(Correct Method to Populate a Select Element with MySQL data, as corrected by @FGraviton)

mysql_select_db("dustin",$con);
$sql="SELECT id,lastname,firstname FROM drivers_0135199";
$result=mysql_query($sql,$con);

echo "<select name='currentdrivers' id='currentdrivers'>";
while($row=mysql_fetch_array($result)){
echo "<option value=\"".$row['id']."\">".$row['lastname'].",".$row['firstname']."</option>\n";
}
echo "</select>";
0

1 Answer 1

3

You have to put </select> outside the while loop.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh man, thanks @FGraviton, I was going cross eyed looking at this thing. It works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.