Jump to content

[SOLVED] dynamically populate a drop down menu


cedtech23

Recommended Posts

I was able to get information out of a table. know I am trying to dynamically populate a drop down menu.

I am having some trouble populating the option value with  $row['f_name'] " " $row['l_name']

The same issue with the option display name. The syntax is not correct, please advise.

 

 

 

select name="provider" id="provider">
<option></option>

<?php
while($row = mysql_fetch_array($result)) {

echo '<option value="'.$row['l_name'].'"'.$selected.">{$row['f_name']}{$row['l_name']}</option>\n";

}
?>
</select>

Try like this

select name="provider" id="provider">
<option></option>
<?php

while($row = mysql_fetch_array($result)) 
{
// store in a variable 
$lastname  = $row['l_name']; 
$firstname = $row['f_name'];
// echo the variables...
echo '<option value="'.$lastname.'"'.$selected.'">'.$firstname.' '.$lastname.'</option>\n';
}
?>
</select>

<select name="provider" id="provider">
<option></option>
<?php

while($row = mysql_fetch_array($result)) 
{
// store in a variable 
$lastname  = $row['l_name']; 
$firstname = $row['f_name'];
// echo the variables...
echo '<option value="'.$lastname.'" '.$selected.'>'.$firstname.' '.$lastname.'</option>\n'; // have a space between $lastname and $selected
}
?>
</select>

 

have a space between $lastname and $selected.. also, is $selected defined?

you were also missing a < at the beginning of the code

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.