$username Posted January 23, 2008 Share Posted January 23, 2008 Hello All, I have a question about this drop down box and pulling from MySQL. I would like to have it auto select the person in the drop down box. But I need it This is what I would like but it does not work. $Owners = "$Contactfname, $Contactlname"; $selected = ($row150['UserFirstName']","$row150['UserLastName']==$Owners )?" selected=\"selected\"":""; Is there something I am missing? $Owners = "$Contactfname, $Contactlname"; <td><strong>Owner:</strong></td> <td> <select name=\"ContactOwner\" size=\"1\">"; $sql150 = "SELECT UserFirstName, UserLastName FROM users"; //$sql150 = "SELECT CompState FROM standardvalues"; if ($result150 = mysql_query($sql150)) { while ($row150 = mysql_fetch_assoc($result150)) { $selected = ($row150['UserFirstName']==$Owners )?" selected=\"selected\"":""; echo "<option value=\"{$row150['UserFirstName']}, {$row150['UserFirstName']}\"{$selected}>{$row150['UserFirstName']}, {$row150['UserFirstName']}</option>"; } } echo " </select> </div></td> Quote Link to comment https://forums.phpfreaks.com/topic/87383-solved-php-mysql-populated-drop-down-box-issue/ Share on other sites More sharing options...
GingerRobot Posted January 23, 2008 Share Posted January 23, 2008 In this line: $Owners = "$Contactfname, $Contactlname"; You have a space after the comma. In this line: $selected = ($row150['UserFirstName']","$row150['UserLastName']==$Owners )?" selected=\"selected\"":""; You dont. Personally i'd use an AND operator anyway: $selected = ($row150['UserFirstName'] == $Contactfname && $row150['UserLastName']==$Contactlname )?" selected=\"selected\"":""; Quote Link to comment https://forums.phpfreaks.com/topic/87383-solved-php-mysql-populated-drop-down-box-issue/#findComment-446998 Share on other sites More sharing options...
$username Posted January 23, 2008 Author Share Posted January 23, 2008 Thanks GingerRobot That fixed it, Brett Quote Link to comment https://forums.phpfreaks.com/topic/87383-solved-php-mysql-populated-drop-down-box-issue/#findComment-447126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.