changing/replacing column values/styles

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

changing/replacing column values/styles

Post by jarow »

I have a column of data that is in all caps that I want to change to first letter capitalized only. what is the best way to do this.

column name = phylum

many thanks
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

If you do not want to have that done before the data is submitted, you could use a trigger in the db to do it.


John M
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

If you are using MySQL, you can make the first character of every value of that column with something like this:

Code: Select all

update tablename
set phylum = concat(upper(substring(phylum,1,1)),lower(substring(phylum,2));
But I would tend to leave the database values as they are, and just display the results as you want using PHP functions:

Code: Select all

$phylum = ucfirst(strtolower($phylum));
This way, you don't have to worry about continually cleaning the database values as new rows are created.
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

Post by jarow »

Thanks Rob,

I will take your advise about leaving the database alone and use the php statement instead, but here´s the problem.

my search fields are all dynamic list fields, which means the values the user selects come directly from the database. Is there a way of formatting this field so that when the database values are viewed in the list they basically conform to your suggestion:

$phylum = ucfirst(strtolower($phylum));

Thanks

Jim
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

How do they come directly from the database? If you are using PHP to read them from the database, just apply the code snippet we've talked about to each value from PHYLUM that is read from the database and before it is echo-ed to the HTML page.

If you have the code that creates the dynamic lists, I'm sure we can help you integrate the code into your programs.
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

Post by jarow »

Hi Rob,

So if option value of my list is <option value="<?php echo $row_rsphylum['phylum']?>" how would I exactly write the snippet and where would I place it?

Thanks

Jim
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

Try this:

Code: Select all

<option value="<?php echo ucfirst(strtolower($row_rsphylum&#1111;'phylum']))?>"
Post Reply