Jump to content

[SOLVED] how to combining 2 db fields into one selection?


j.g.

Recommended Posts

Hello List!

 

I've got an issue that I'm hoping someone can help me with...

 

In my db I have 2 fields: first_name and last_name & I want to combine these 2 fields in my drop-down menu.

 

What I have now is showing only the first_name -- I know that it needs to go into the third option in here, I'm just not sure how to get both of them into it. I can get the first_name OR last_name, but not combined.

 

$show_blank = true;
$query = "SELECT users.first_name, users.last_name, classification.* FROM users, classification, address ".
             "WHERE type = 'Membership' ".
             "AND member_searchable = '1' ".
             "AND users.classification_id = classification.classification_id ".
             "AND users.work_address_id != '' ".
             "AND users.work_address_id = address.address_id ".
             "ORDER BY users.last_name";
echo query_dropdown($query, 'first_name', 'first_name', "name", $_REQUEST["name"], $show_blank);

 

Any insight and help that you could give me would be greatly appreciated!

 

Thanks,

-j.g.

you could concatenate them within the query, and give them another alias so as to preserve the first and last names individually (in case you use them elsewhere):

 

$query = "SELECT users.first_name, users.last_name, CONCAT(users.first_name, ' ', users.last_name) AS full_name classification.* FROM users, classification, address ".
             "WHERE type = 'Membership' ".
             "AND member_searchable = '1' ".
             "AND users.classification_id = classification.classification_id ".
             "AND users.work_address_id != '' ".
             "AND users.work_address_id = address.address_id ".
             "ORDER BY users.last_name";

 

you're then free to use full_name however you please.

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.