Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Shorten a Name

  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Shorten a Name

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

  • #2
    New Coder
    Join Date
    Mar 2010
    Posts
    26
    Thanks
    3
    Thanked 1 Time in 1 Post
    Code:
    $words = explode(" ",$sentence);
    echo $words[0];

  • Users who have thanked Goldfish for this post:

    shanparker (03-12-2010)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

    Edit:
    Looks like goldfish snuck in there with an example too
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    New Coder
    Join Date
    Sep 2004
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    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.

    Edit:
    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.

  • #5
    New Coder
    Join Date
    Sep 2004
    Posts
    54
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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/w...name/index.php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •