How to simplify my country select menu PHP/mysql

Posted by user342391 on Stack Overflow See other posts from Stack Overflow or by user342391
Published on 2010-06-09T11:35:41Z Indexed on 2010/06/09 11:52 UTC
Read the original article Hit count: 337

Filed under:
|
|
|

I have a select menu that displays countries. It looks at the DB and judging by the value in the db shows the option as selected. Is there a simpler way off doing this than:

if ($country == 'AG') {echo '<option value="AG" selected="selected">Antigua</option>';} 
else {echo '<option value="AG">Antigua</option>';};

if ($country == 'AR') {echo '<option value="AR" selected="selected">Argentina</option>';} 
else {echo '<option value="AR">Argentina</option>';};

if ($country == 'AM') {echo '<option value="AM" selected="selected">Armenia</option>';} 
else {echo '<option value="AM">Armenia</option>';};

if ($country == 'AW') {echo '<option value="AW" selected="selected">Aruba</option>';} 
else {echo '<option value="AW">Aruba</option>';};

if ($country == 'AU') {echo '<option value="AU" selected="selected">Australia</option>';} 
else {echo '<option value="AU">Australia</option >';};

if ($country == 'AT') {echo '<option value="AT" selected="selected">Austria</option>';} 
else {echo '<option value="AT">Austria</option>';};

if ($country == 'AZ') {echo '<option value="AZ" selected="selected">Azerbaijan</option>';} 
else {echo '<option value="AZ">Azerbaijan</option>';};

if ($country == 'BS') {echo '<option value="BS" selected="selected">Bahamas</option>';} 
else {echo '<option value="BS">Bahamas</option>';};

if ($country == 'BH') {echo '<option value="BH" selected="selected">Bahrain</option>';} 
else {echo '<option value="BH">Bahrain</option>';};

There are a lot of countries and doing this would be madness wouldn't it????

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql