In a message dated 7/1/2003 3:56:28 PM Pacific Daylight Time, [EMAIL PROTECTED] writes:
>Does anyone know of any built in functions or options for the US states? >I want to make a drop down menu and some other things which have the 50 >states in it. Is there any shortcut for this with PHP, or do I need to >do it all manually in HTML? Please let me know. Thanks. Here's code that will create a dropdown list of states. It uses functions called getNames and getCodes that create arrays of the state names and state codes. The functions that create the arrays are attached. <select name="state"> <?php $stateName=getNames(); $stateCode=getCodes(); for ($n=1;$n<=50;$n++) { $state=$stateName[$n]; $scode=$stateCode[$n]; echo "<option value='$scode'"; if ($scode== "AL") echo " selected"; echo ">$state\n"; } ?> </select> Good luck, Janet
<?php function getCodes() { $stateCode = array(1=> "AL" , "AK" , "AZ" , "AR" , "CA" , "CO" , "CT" , "DE" , "DC" , "FL" , "GA" , "HI" , "ID" , "IL" , "IN" , "IA" , "KS" , "KY" , "LA" , "ME" , "MD" , "MA" , "MI" , "MN" , "MS" , "MO" , "MT" , "NE" , "NV" , "NH" , "NJ" , "NM" , "NY" , "NC" , "ND" , "OH" , "OK" , "OR" , "PA" , "RI" , "SC" , "SD" , "TN" , "TX" , "UT" , "VT" , "VA" , "WA" , "WV" , "WI" , "WY" ); return $stateCode; } function getNames() { $stateName = array(1=> "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Ontario", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"); return $stateName; } ?>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php