Can someone explain to me the syntax and write the code to retain the value for my drop down array in HTML and PHP
Php portion:
<?php
$COL_array = array(
‘AK – Anchorage’ => 131.046,
‘AK – Fairbanks’ => 138.45,
‘AK – Juneau’ => 140.675,
‘AK – Kodiak’ => 128.805,
‘AL – Anniston-Calhoun County’ => 92.862,
‘AL – Auburn-Opelika’ => 99.881,
‘AL – Birmingham’ => 87.181,
‘AL – Decatur-Hartselle’ => 91.972,
‘AL – Dothan’ => 92.048,
‘AL – Florence’ => 92.006,
‘AL – Huntsville’ => 94.996,
‘AL – Mobile’ => 92.168,
‘AL – Montgomery’ => 97.07,
‘AR – Conway’ => 87.571,
‘AR – Fayetteville’ => 86.254,
‘AR – Hot Springs’ => 94.849,
‘AR – Jonesboro’ => 89.333,
‘AR – Little Rock-North Little Rock’ => 96.453,
‘AZ – Flagstaff’ => 112.498,
‘AZ – Lake Havasu City’ => 108.865,
‘AZ – Phoenix’ => 94.09,
‘AZ – Prescott-Prescott Valley’ => 100.78,
‘AZ – Sierra Vista’ => 99.534,
‘AZ – Tucson’ => 95.407,
‘CA – Bakersfield’ => 97.294,
‘CA – Fresno’ => 110.931,
‘CA – Los Angeles-Long Beach’ => 131.557,
‘CA – Oakland’ => 136.176,
‘CA – Orange County’ => 143.256,
‘CA – Palm Springs’ => 122.346,
‘CA – Riverside City’ => 111.876,
‘CA – San Diego’ => 130.876,
‘CA – San Francisco’ => 161.508,
‘CA – San Jose’ => 152.657,
‘CA – Truckee-Nevada County’ => 145.179,
‘CO – Colorado Springs’ => 93.104,
‘CO – Denver’ => 105.063,
‘CO – Glenwood Springs’ => 109.033,
‘CO – Grand Junction’ => 99.176,
‘CO – Gunnison’ => 113.621,
‘CO – Pueblo’ => 86.472,
‘CT – Hartford’ => 123.307,
‘CT – New Haven’ => 127.827,
‘CT – Stamford’ => 147.922,
‘DC – Washington-Arlington-Alexandria’ => 147.017,
‘DE – Dover’ => 101.021,
‘DE – Wilmington’ => 107.972,
‘FL – Bradenton’ => 96.856,
‘FL – Cape Coral-Fort Myers’ => 95.501,
‘FL – Daytona Beach’ => 96.206,
‘FL – Fort Lauderdale’ => 109.924,
‘FL – Gainesville’ => 99.454,
‘FL – Jacksonville’ => 95.155,
‘FL – Miami-Dade County’ => 108.457,
‘FL – Orlando’ => 96.925,
‘FL – Palm Coast-Flagler County’ => 90.108,
‘FL – Punta Gorda-Charlotte Co’ => 93.751,
‘FL – Sarasota’ => 99.864,
‘FL – Tampa’ => 91.501,
‘FL – Vero Beach-Indian River’ => 97.827,
‘GA – Albany’ => 91.139,
‘GA – Atlanta’ => 99.104,
‘GA – Augusta-Aiken’ => 92.059,
‘GA – Douglas’ => 90.088,
‘GA – Duluth-Gwinnett County’ => 98.708,
‘GA – Marietta’ => 96.297,
‘GA – Savannah’ => 91.5,
‘GA – Valdosta’ => 95.022,
‘HI – Honolulu’ => 167.163,
‘IA – Ames’ => 95.653,
‘IA – Burlington’ => 92.908,
‘IA – Cedar Rapids’ => 93.39,
‘IA – Davenport-Moline-Rock Is’ => 98.062,
‘IA – Des Moines’ => 90.504,
‘IA – Dubuque’ => 94.449,
‘IA – Iowa City’ => 101.549,
‘IA – Mason City’ => 93.305,
‘IA – Waterloo-Cedar Falls’ => 93.072,
‘ID – Boise’ => 94.573,
‘ID – Idaho Falls’ => 88.256,
‘ID – Twin Falls’ => 90.384,
‘IL – Carbondale’ => 94.396,
‘IL – Champaign-Urbana’ => 99.063,
‘IL – Chicago’ => 114.111,
‘IL – Danville’ => 89.335,
‘IL – Decatur’ => 90.728,
‘IL – Galesburg’ => 91.217,
‘IL – Joliet-Will County’ => 100.117,
‘IL – Peoria’ => 95.642,
‘IL – Quincy’ => 95.152,
‘IL – Rockford’ => 89.872,
‘IL – Springfield’ => 89.597,
‘IN – Elkhart-Goshen’ => 93.409,
‘IN – Evansville’ => 94.097,
‘IN – Fort Wayne-Allen County’ => 95.305,
‘IN – Lafayette’ => 91.959,
‘IN – Muncie’ => 88.352,
‘IN – Richmond’ => 85.668,
‘IN – South Bend’ => 92.687,
‘KS – Dodge City’ => 92.812,
‘KS – Garden City’ => 96.178,
‘KS – Hutchinson’ => 92.927,
‘KS – Manhattan’ => 94.696,
‘KS – Salina’ => 88.374,
‘KS – Topeka’ => 93.491,
‘KS – Wichita’ => 91.707,
‘KY – Covington’ => 90.091,
‘KY – Lexington’ => 91.926,
‘KY – Louisville’ => 92.535,
‘KY – Paducah’ => 92.909,
‘LA – Baton Rouge’ => 92.768,
‘LA – Hammond’ => 92.387,
‘LA – Houma-Terrebonne Parish’ => 97.78,
‘LA – Lafayette’ => 99.465,
‘LA – Lake Charles’ => 94.996,
‘LA – Monroe’ => 93.577,
‘LA – Shreveport-Bossier City’ => 99.056,
‘LA – Slidell-St. Tammany Parish’ => 95.77,
‘MA – Boston’ => 137.082,
‘MA – Pittsfield’ => 102.146,
‘MD – Baltimore’ => 117.538,
‘MD – Bethesda-Gaithersburg-Frederick’ => 131.942,
‘ME – Portland’ => 112.529,
‘MI – Ann Arbor’ => 102.232,
‘MI – Detroit’ => 95.844,
‘MI – Kalamazoo’ => 87.351,
‘MN – Mankato’ => 95.082,
‘MN – Minneapolis’ => 111.592,
‘MN – Rochester’ => 105.254,
‘MN – St. Cloud’ => 95.704,
‘MN – St. Paul’ => 110.355,
‘MO – Columbia’ => 91.473,
‘MO – Jefferson City’ => 97.608,
‘MO – Joplin’ => 90.498,
‘MO – Kansas City’ => 99.799,
‘MO – Springfield’ => 89.806,
‘MO – St. Louis’ => 91.043,
‘MS – Hattiesburg’ => 93.234,
‘MS – Jackson’ => 96.881,
‘MS – Pascagoula’ => 91.801,
‘MS – Tupelo’ => 88.808,
‘MT – Bozeman’ => 99.166,
‘MT – Kalispell’ => 100.131,
‘NC – Asheville’ => 101.424,
‘NC – Burlington’ => 95.832,
‘NC – Chapel Hill’ => 115.338,
‘NC – Charlotte’ => 92.743,
‘NC – Dare County’ => 108.623,
‘NC – Durham’ => 90.81,
‘NC – Fayetteville’ => 96.197,
‘NC – Gastonia’ => 91.667,
‘NC – Greenville’ => 96.325,
‘NC – Jacksonville’ => 96.541,
‘NC – Kinston’ => 93.589,
‘NC – Marion-McDowell County’ => 94.329,
‘NC – Raleigh’ => 92.842,
‘NC – Thomasville-Lexington’ => 89.105,
‘NC – Wilmington’ => 98.681,
‘NC – Winston-Salem’ => 90.181,
‘ND – Fargo-Moorhead’ => 94.056,
‘ND – Minot’ => 104.066,
‘NE – Hastings’ => 92.887,
‘NE – Lincoln’ => 93.232,
‘NE – Omaha’ => 88.626,
‘NH – Manchester’ => 120.482,
‘NJ – Bergen-Passaic’ => 128.224,
‘NJ – Middlesex-Monmouth’ => 124.492,
‘NJ – Newark-Elizabeth’ => 131.739,
‘NM – Carlsbad’ => 97.486,
‘NM – Farmington’ => 97.856,
‘NM – Las Cruces’ => 99.018,
‘NM – Los Alamos’ => 106.236,
‘NM – Rio Rancho’ => 97.375,
‘NV – Las Vegas’ => 98.764,
‘NV – Reno-Sparks’ => 92.201,
‘NY – Albany’ => 110.637,
‘NY – Buffalo’ => 99.511,
‘NY – Dutchess County’ => 122.633,
‘NY – Ithaca’ => 103.892,
‘NY – Nassau County’ => 139.091,
‘NY – New York (Brooklyn)’ => 185.015,
‘NY – New York (Manhattan)’ => 223.425,
‘NY – New York (Queens)’ => 154.873,
‘NY – Plattsburgh’ => 101.316,
‘NY – Rochester’ => 98.845,
‘OH – Akron’ => 98.984,
‘OH – Ashland’ => 88.874,
‘OH – Cincinnati’ => 92.902,
‘OH – Cleveland’ => 99.221,
‘OH – Columbus’ => 91.686,
‘OH – Dayton’ => 93.494,
‘OH – Findlay’ => 96.912,
‘OH – Lima’ => 93.6,
‘OH – Wooster’ => 89.819,
‘OH – Youngstown-Warren’ => 90.685,
‘OK – Ardmore’ => 84.017,
‘OK – Edmond’ => 93.842,
‘OK – Enid’ => 93.052,
‘OK – Muskogee’ => 87.529,
‘OK – Norman’ => 90.983,
‘OK – Oklahoma City’ => 91.072,
‘OK – Ponca City’ => 89.808,
‘OK – Pryor Creek’ => 85.206,
‘OK – Stillwater’ => 92.122,
‘OK – Tulsa’ => 89.581,
‘OR – Eugene’ => 109.547,
‘OR – Klamath Falls’ => 98.023,
‘OR – Portland’ => 117.53,
‘PA – Allentown’ => 105.735,
‘PA – Harrisburg’ => 102.365,
‘PA – Indiana County’ => 94.535,
‘PA – Johnstown’ => 94.316,
‘PA – Philadelphia’ => 123.645,
‘PA – Pittsburgh’ => 94.863,
‘PA – Williamsport-Lycoming Co’ => 95.472,
‘PA – York County’ => 102.912,
‘RI – Providence’ => 125.148,
‘SC – Anderson’ => 90.147,
‘SC – Beaufort’ => 99.282,
‘SC – Camden’ => 98.57,
‘SC – Charleston-N Charleston’ => 97.313,
‘SC – Columbia’ => 94.632,
‘SC – Greenville’ => 92.506,
‘SC – Hilton Head Island’ => 115.133,
‘SC – Myrtle Beach’ => 95.526,
‘SC – Sumter’ => 93.266,
‘SD – Pierre’ => 100.449,
‘SD – Sioux Falls’ => 95.677,
‘TN – Chattanooga’ => 93.894,
‘TN – Cleveland’ => 92.591,
‘TN – Cookeville’ => 86.161,
‘TN – Dyersburg’ => 89.267,
‘TN – Jackson-Madison County’ => 90.4,
‘TN – Knoxville’ => 89.482,
‘TN – Memphis’ => 84.449,
‘TN – Morristown’ => 91.306,
‘TN – Murfreesboro-Smyrna’ => 87.628,
‘TN – Nashville-Franklin’ => 89.971,
‘TX – Amarillo’ => 94.336,
‘TX – Athens-Henderson County’ => 89.163,
‘TX – Austin’ => 93.236,
‘TX – Beaumont’ => 97.581,
‘TX – Brazoria County’ => 86.962,
‘TX – Brownsville’ => 86.534,
‘TX – Bryan-College Station’ => 92.593,
‘TX – Conroe’ => 90.639,
‘TX – Corpus Christi’ => 90.083,
‘TX – Dallas’ => 96.898,
‘TX – Denton’ => 92.807,
‘TX – El Paso’ => 91.73,
‘TX – Fort Worth’ => 93.314,
‘TX – Harlingen’ => 81.551,
‘TX – Houston’ => 90.899,
‘TX – Lubbock’ => 89.516,
‘TX – McAllen’ => 84.994,
‘TX – Midland’ => 95.602,
‘TX – Nacogdoches’ => 95.478,
‘TX – Odessa’ => 90.061,
‘TX – Paris’ => 92.402,
‘TX – Plano’ => 96.052,
‘TX – Round Rock’ => 91.07,
‘TX – San Angelo’ => 89.559,
‘TX – San Antonio’ => 92.909,
‘TX – San Marcos’ => 87.979,
‘TX – Seguin’ => 92.309,
‘TX – Sherman-Denison’ => 88.188,
‘TX – Temple’ => 85.912,
‘TX – Texarkana’ => 90.48,
‘TX – Tyler’ => 95.044,
‘TX – Waco’ => 84.751,
‘TX – Weatherford’ => 92.033,
‘TX – Wichita Falls’ => 89.416,
‘UT – Cedar City’ => 88.215,
‘UT – Ogden’ => 90.43,
‘UT – Provo-Orem’ => 90.297,
‘UT – Salt Lake City’ => 95.081,
‘UT – St. George’ => 91.449,
‘VA – Blacksburg’ => 95.031,
‘VA – Charlottesville’ => 104.679,
‘VA – Danville City’ => 91.795,
‘VA – Hampton Roads-SE Virginia’ => 104.948,
‘VA – Harrisonburg’ => 97.283,
‘VA – Lexington-Buena Vista-Rockbridge’ => 93.982,
‘VA – Lynchburg’ => 91.908,
‘VA – Richmond’ => 99.609,
‘VA – Roanoke’ => 93.316,
‘VA – Staunton-Augusta County’ => 94.97,
‘VA – Winchester’ => 102.415,
‘VT – Burlington-Chittenden Co’ => 121.789,
‘WA – Everett’ => 109.571,
‘WA – Kennewick-Richland-Pasco’ => 98.265,
‘WA – Moses Lake’ => 93.009,
‘WA – Olympia’ => 104.985,
‘WA – Seattle’ => 115.688,
‘WA – Spokane’ => 94.501,
‘WA – Tacoma’ => 106.179,
‘WA – Vancouver’ => 98.642,
‘WA – Yakima’ => 92.596,
‘WI – Appleton’ => 93.54,
‘WI – Eau Claire’ => 91.274,
‘WI – Janesville’ => 97.755,
‘WI – Madison’ => 107.069,
‘WI – Marshfield’ => 96.851,
‘WI – Milwaukee-Waukesha’ => 99.57,
‘WI – Wausau’ => 95.104,
‘WV – Charleston’ => 94.088,
‘WV – Martinsburg-Berkeley County’ => 91.859,
‘WV – Morgantown’ => 105.14,
‘WY – Cheyenne’ => 95.86
);
$key = null;
$town1 = isset($_REQUEST[‘town1’]) ? $_REQUEST[‘town1’]: null;
?>
HTML Portion:
<html>
<form>
<select name=”town1″>
<? foreach ($COL_array as $key =>$value) { ?>
<option value=”<? echo($key); ?>”><? echo($key); ?></option>
<? ;} ?>
</select>
</form>
</html>
Expert Answer
The code which you wrote is correct. So to get the value of the selected value from the drop down you need the piece of line.
$selected_value = $_POST[‘town1′] –> gets the selected value by using name of the select tage
you can then output the selected value using the echo statement. I hope it works