Capitalize First Letter of Record: Easy as...?

terp

Beta Tester Extraordinaire
...just one of those things that make me go, "hmmmm." Is it easy to fire a little sql to save a form response with a capital letter, if lower-case was used?

So, for example, I have a field for 'city' and a user enters "fredericksburg," but other users enter it as "Fredericksburg," I thought it would be a nice touch to have all first letters capitalized; but I could see this getting complicated (for someone like me) if there is more than a one word (like new York city) response.

Would something as simple as this work?

Code:
RETURN upper(left(@string, 1)) + right(@string, len(@string) - 1)

Okay, it doesn't work, as I tried it, so thought I would ask... ;)
 
Are you talking about using a form submit script?

If so, PHP has a 'ucfirst' that might be useful. Something like ...

PHP:
$sentence = strtolower($this->_data['table___element']); // convert whole thing to lower case
preg_replace('#\s+#',' ',$sentence); // reduce multiple space to single
$sentence_array = explode(' ', $sentence);
foreach ($sentence_array as $word) {
    $word = ucfirst($word);
    $new_sentence_array[] = $word;
}
$this->_data['table___element'] = implode(' ',$new_sentence_array);
For some examples of more robust routines for ucfirst'ing a sentence, check the user comments on:

http://www.php.net/ucfirst

-- hugh
 
Thanks, boss...will check that out; all the explode and implode stuff is a little more exciting that the nonsense I posted...will play around with it tonight (after I leave this cesspool for the day). ;)
 
The explode/implode stuff is to deal with multiple words. It 'explodes' the string into an array of words. Then it loops through the array, ucfirst'ing each word and adding it to a new array. Then it 'implodes' the new array back into a string, which it stuffs back in your element.

Of course, taking care of any existing data which has already been stored in the db table would be a little trickier. Probably easier to deal with those by hand!

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top