I'm having trouble trying to select a specific drop down box option based on what's been saved to a database.
The code looks like this:
The goal is simple. I have 2 tables inside of a database. "clients" and "jobs".
When adding/editing a job you can choose which client it is associated with. The drop down box is being populated with all client names.
What I'd like to do is have the specific client selected by default when someone edits an existing job.
ie. If they created a job and "Joe Blow" is the client, then when the 'edit job' page is loaded it will select "Joe Blow" by default.
I'm pretty much a PHP newbie but I just can't get this to work. When I do the $firstname + $lastname compare to $client it keeps returning true and the SELECTED option is being written for each client.
When I do an echo on $firstname + $lastname and $client it looks right.
An example of an echo result is this:
Joe Blow ... Jim Smith
Jim Smith ... Jim Smith
John Doe ... Jim Smith
To me this says all of the variables are correct. It should only output the SELECTED option for Jim Smith, yet the code is selecting them all. Why?
The code looks like this:
Code:
while ($row = mysql_fetch_array($result_clientlist)) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];
if (($firstname + " " + $lastname) == $client)
{
echo "<OPTION VALUE=\"$firstname $lastname\" SELECTED=\"selected\">$firstname $lastname</OPTION>\n";
}
else
{
echo "<OPTION VALUE=\"$firstname $lastname\">$firstname $lastname</OPTION>\n";
}
}
The goal is simple. I have 2 tables inside of a database. "clients" and "jobs".
When adding/editing a job you can choose which client it is associated with. The drop down box is being populated with all client names.
What I'd like to do is have the specific client selected by default when someone edits an existing job.
ie. If they created a job and "Joe Blow" is the client, then when the 'edit job' page is loaded it will select "Joe Blow" by default.
I'm pretty much a PHP newbie but I just can't get this to work. When I do the $firstname + $lastname compare to $client it keeps returning true and the SELECTED option is being written for each client.
When I do an echo on $firstname + $lastname and $client it looks right.
An example of an echo result is this:
Joe Blow ... Jim Smith
Jim Smith ... Jim Smith
John Doe ... Jim Smith
To me this says all of the variables are correct. It should only output the SELECTED option for Jim Smith, yet the code is selecting them all. Why?