Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.