...

View Full Version : Shorten a Name



shanparker
03-12-2010, 04:55 PM
I've done this before but now cannot think of how I did it or even turn anything up on a google search about how to.

I have a simple database that holds a name field of "First Name Last Name" and when I pull this field into the page I want it to just echo the "First Name" and not show the last name.

Simple I know. Beating my head against the keyboard here...

Goldfish
03-12-2010, 05:04 PM
$words = explode(" ",$sentence);
echo $words[0];

Fou-Lu
03-12-2010, 05:08 PM
You can explode those two words if they are always only two words in the block. The better solution would be to convert you're database to hold two fields; one for the first name and one for the second name. This will allow you to properly index these fields for quick lookups on either first or last name searches.


Looks like goldfish snuck in there with an example too

shanparker
03-12-2010, 05:23 PM
You can explode those two words if they are always only two words in the block. The better solution would be to convert you're database to hold two fields; one for the first name and one for the second name. This will allow you to properly index these fields for quick lookups on either first or last name searches.


Looks like goldfish snuck in there with an example too


Normally I would provide two fields but I was working with a somewhat limited area and I wanted to make the form look as absolutely simple as possible so I thought having both included in one field would be a good way of doing that. I'm not really asking the database to do anything complicated other than to gather information and spit a few things out. So it doesn't need to be terribly flexible.

shanparker
03-12-2010, 05:24 PM
Thanks for the help. Here is where I was applying it. In the diagonal background bar in the middle. Since I'm not asking users if I can display their votes I didn't want their full name to be shown, however for data mining it was helpful to get their last name from their entry.

http://www.mascotsmeanbusiness.com/whatsmyname/index.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum