Can I Specify Strings for MySql Table Values?

Posted by afterimagedesign on Stack Overflow See other posts from Stack Overflow or by afterimagedesign
Published on 2012-10-10T03:07:46Z Indexed on 2012/10/10 3:37 UTC
Read the original article Hit count: 701

Filed under:
|
|

I have a MySql table that stores the users state and city from a list of states and cities. I specifically coded each state as their two letter shortened version (like WA for Washington and CA for California) and every city has the two letter abbreviation and the city name formated like this: Boulder Colorado would be CO-boulder and Salt Lake City, Utah would be UT-salt-lake-city as to avoid different states with same city name. The PHP inserts the value (UT-salt-lake-city) under the column City, but when I call the variable through PHP, it displays like this: Your location is: UT-salt-lake-city, Utah. To solve this, I've been making this list of variables

    if ($city == "AL-auburn") { $city = "Auburn"; }
    else if ($city == "AL-birmingham") { $city = "Birmingham"; }
    else if ($city == "GA-columbus") { $city = "Columbus"; $state = "Georgia"; }
    else if ($city == "AL-dothan") { $city = "Dothan"; }
    else if ($city == "AL-florence") { $city = "Forence"; }
    else if ($city == "AL-muscle-shoals") { $city = "Muscle Shoals"; }
    else if ($city == "AL-gadsden-anniston") { $city = "Gadsden Anniston"; }
    else if ($city == "AL-huntsville") { $city = "Huntsville"; }
    else if ($city == "AL-decatur") { $city = "Decatur"; }
    else if ($city == "AL-mobile") { $city = "Mobile"; }
    else if ($city == "AL-montgomery") { $city = "Montgomery"; }
    else if ($city == "AL-tuscaloosa") { $city = "Tuscaloosa"; }

Is there a way I can shorten this process or at least call it from a separate file so I don't have to copy/paste every time I want to call the location?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql