View Full Version : Populating Drop Down from MySQL using PHP

06-22-2006, 01:39 AM
I am trying to populate a drop down menu of MySQL data using PHP and I have hit a snag. I think its probably something simple that a freah pair of eyes could pick out right away that I am just not seeing... For some reason only the "firstname" part of the data is populating in the drop down and I can't figure out why. When I try to make changes to the echo lines to correct this, nothing shows up including the "firstname" data. The code is below...


//connect to MySQL

$connect = mysql_connect("localhost","xxx","xxx") or
die ("Could not connect to database.");

//choose the database


//get data from MySQL database

$result = mysql_query('SELECT clientid, firstname, lastname FROM people')
or die (mysql_error());

//populate drop down menu with data from MySQL database

echo '<select name="clientlist">';
while ($row = mysql_fetch_assoc($result))
echo '<option value="' . $row['clientid'] . '">' . $row['firstname']. ' ' . $row['lasttname'] . '</option>';
echo '</select>';




06-22-2006, 03:06 AM
Why not solve it like this:

SELECT clientid, concat(firstname, ' ', lastname) as fullname FROM people

echo '<option value="' . $row['clientid'] . '">' . $row['fullname']. '</option>';

06-23-2006, 12:17 AM
I could do that I supposed, but that still doesn't explain why only the middle part of the whole section of code was appearing in the drop down. Does the drop down have a problem pulling INT value from the database or something like that perhaps, it doesn't make sense...