简体   繁体   中英

Convert 2 letter country code to country name

I have a big list of countries, the user selects which country they are from, I then save the 2 letter code to the database. When I later want to display which country that user is from on another page I can get the 2 letter code from the database, but how should I convert it back to the name of the country? It seems such a waste to have a big switch statement?

<select name='country' value={country} onChange={onChange}>
                <option value=''>Select...</option>
                <option value='AX'>Aaland Islands</option>
                <option value='AF'>Afghanistan</option>
                <option value='AL'>Albania</option>
                <option value='DZ'>Algeria</option>
                <option value='AS'>American Samoa</option>
                <option value='AD'>Andorra</option>
                <option value='AO'>Angola</option>
                <option value='AI'>Anguilla</option>
                <option value='AQ'>Antarctica</option>
                <option value='AG'>Antigua And Barbuda</option>

why don't you try to use a SELECT CASE

CASE

WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result

END;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM