Page 1 of 1

Spaces in drop-down box

Posted: Mon Apr 20, 2009 8:09 pm
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

Re: Spaces in drop-down box

Posted: Mon Apr 20, 2009 8:35 pm
by it2051229
then do something like:

Code: Select all

$options.="<OPTION VALUE=$docid $surname>".$firstname." ".$surname;

Re: Spaces in drop-down box

Posted: Mon Apr 20, 2009 9:35 pm
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.

Re: Spaces in drop-down box

Posted: Tue Apr 21, 2009 5:16 am
by inf
Oh thankyou for the support, im beginning to see how things work now :)