Spaces in drop-down box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
inf
Forum Newbie
Posts: 5
Joined: Mon Apr 20, 2009 7:52 pm

Spaces in drop-down box

Post by inf »

My problem is simple really, but i cant figure it out..

Image

I want the name to appear as Sean Lister, not SeanLister

Code: Select all

<?
 
$sql="SELECT id, firstname, surname, room, direction FROM doctors";
$result=mysql_query($sql);
 
$options="";
 
while ($row=mysql_fetch_array($result)) {
 
    $docid=$row["id"];
    $firstname=$row["firstname"];
    $surname=$row["surname"];
    $options.="<OPTION VALUE=$docid $surname>".$firstname.$surname;
}
?>
I am trying to load from two variables, $firstname and $surname but i need a space between them both?
Any suggestions?
Thanks thanks :D
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Spaces in drop-down box

Post by it2051229 »

then do something like:

Code: Select all

$options.="<OPTION VALUE=$docid $surname>".$firstname." ".$surname;
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Spaces in drop-down box

Post by McInfo »

The code is also missing a closing option tag and quotes around the value string, and it seems unusual that $surname would be included in the option value.

Code: Select all

$options .= '<option value="' . $docid . '">' . $firstname . ' ' . $surname . '</option>';
or

Code: Select all

$options .= "<option value=\"$docid\">$firstname $surname</option>";
or

Code: Select all

$options .= "<option value='$docid'>$firstname $surname</option>";
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Mon Jun 14, 2010 4:06 pm, edited 1 time in total.
inf
Forum Newbie
Posts: 5
Joined: Mon Apr 20, 2009 7:52 pm

Re: Spaces in drop-down box

Post by inf »

Oh thankyou for the support, im beginning to see how things work now :)
Post Reply