1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Change uppercase entries to lowercase

Discussion in 'MySQL' started by guerilla, Jun 28, 2007.

  1. #1
    Guys, I have a MySQL db table with an entire column of names, and unfortunately, they are all capitalized.

    I'm wondering if there is a query I could run to alter the contents of that column, converting every character after the first to lowercase.

    Example,
    Current Entry

    MICHIGAN


    Converted Entry

    Michigan

    Thanks in advance.
     
    guerilla, Jun 28, 2007 IP
    Bebicul, gemini181, Briant and 3 others like this.
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    there is no such function like ucfirst (php)

    so , a solution will be this:

     
    gibex, Jun 28, 2007 IP
    guerilla likes this.
  3. guerilla

    guerilla Notable Member

    Messages:
    9,066
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    200
    #3
    Unfortunately, I'm getting an error. :(
    
    select concat(upper(substr(name,1,1)), lower(substr(name,2,length(name)))) from namestable
    Code (markup):
     
    guerilla, Jun 28, 2007 IP
    Briant likes this.
  4. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #4
    That command is available from 4.1+ (substr is defined from 4.1.1), so only choice is to use PHP or mysql 4.1+

    Anyway, Mysql 4.0.X will be discontinued.
     
    gibex, Jun 28, 2007 IP
  5. guerilla

    guerilla Notable Member

    Messages:
    9,066
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    200
    #5
    Damn hostgator. Thanks.
     
    guerilla, Jun 28, 2007 IP
  6. guerilla

    guerilla Notable Member

    Messages:
    9,066
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    200
    #6
    I've got the above query working on the db, using an install of WAMP.

    I feel so stupid asking this, but what would an update query for the above select query look like?

    Thanks in advance. Rep forthcoming for answers.
     
    guerilla, Jun 30, 2007 IP
  7. Transcendent

    Transcendent Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Wait, you want to actually change the value? Or want to output it differently?

    If it's the former, just run it from a PHP script:

    
    $selectquery=mysql_query("SELECT * from sometable");
    
     while($doupdate = mysql_fetch_array($selectquery))
       {
    $newentry = ucfirst(strtolower($doupdate[entry]));
     mysql_query("UPDATE sometable set entry='$newentry' where id='$doupdate[id]'");
       }
    
    PHP:
    Hope that helps.
     
    Transcendent, Jun 30, 2007 IP
  8. guerilla

    guerilla Notable Member

    Messages:
    9,066
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    200
    #8
    Yes, I actually want to change the values.

    I tried via PHP and it yields no result unfortunately. Thanks just the same.
     
    guerilla, Jul 1, 2007 IP
  9. Transcendent

    Transcendent Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Well, I hope you didn't just paste the code exactly!

    The script I posted will work considering you've established a connection with the DB, and you've changed my values to suit yours.
     
    Transcendent, Jul 1, 2007 IP
  10. guerilla

    guerilla Notable Member

    Messages:
    9,066
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    200
    #10
    I connected to the DB, I changed the tablename.

    What did I miss?
     
    guerilla, Jul 1, 2007 IP
    Briant likes this.
  11. Transcendent

    Transcendent Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    And you also changed the table values?
    It works, I just tried it. There's no reason why it shouldn't. :)
     
    Transcendent, Jul 1, 2007 IP
  12. guerilla

    guerilla Notable Member

    Messages:
    9,066
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    200
    #12
    You have me at a loss. Which values are speaking about? entry?
     
    guerilla, Jul 1, 2007 IP
    Briant likes this.
  13. gemini181

    gemini181 Well-Known Member

    Messages:
    2,883
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    155
    #13
    Did you get a working answer to the original question?
     
    gemini181, Sep 29, 2007 IP
    guerilla and Briant like this.
  14. guerilla

    guerilla Notable Member

    Messages:
    9,066
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    200
    #14
    No, sorry I didn't. I'm slowly learning PHP and MySQL. I think this is easier if I just use a function like ucfirst() in the display code.
     
    guerilla, Sep 29, 2007 IP