Jump to content

[SOLVED] PHP MySQL populated drop down box issue.


$username

Recommended Posts

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>

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\"":"";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.