Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-22-2006, 12:39 AM   PM User | #1
joviyach
New Coder

 
Join Date: Sep 2005
Location: Steger, IL
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
joviyach is an unknown quantity at this point
Question Populating Drop Down from MySQL using PHP

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...

PHP Code:
<?php

//connect to MySQL

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

//choose the database

mysql_select_db("clients");

//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>';

?>
Thanks,

Jim
__________________
Jim
joviyach is offline   Reply With Quote
Old 06-22-2006, 02:06 AM   PM User | #2
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
Why not solve it like this:

Code:
SELECT clientid, concat(firstname, ' ', lastname) as fullname FROM people
PHP Code:
echo '<option value="' $row['clientid'] . '">' $row['fullname']. '</option>'
guelphdad is offline   Reply With Quote
Old 06-22-2006, 11:17 PM   PM User | #3
joviyach
New Coder

 
Join Date: Sep 2005
Location: Steger, IL
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
joviyach is an unknown quantity at this point
Question

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...
__________________
Jim
joviyach is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:54 AM.


Advertisement
Log in to turn off these ads.