horseatingweeds Posted July 31, 2007 Share Posted July 31, 2007 My for loop is simply printing out the array. I'm trying to make it produce option inputs. Anyone see what I'm doing wrong? $state_arr = explode("|", $state); for ($i=0; $i < (count($state_arr)); $i++) { echo "<option value='" . $state_arr[$i] . "'>" . $state_arr[$i] . "</option>"; } $state = '\ UNITED STATES|\ Alaska|\ Alabama|\ Arkansas|\ American Samoa|\ Arizona|\ California|\ Colorado|\ Connecticut|\ D.C.|\ Delaware|\ Florida|\ Georgia|\ Hawaii|\ Iowa|\ Idaho|\ Illinois|\ Indiana|\ Kansas|\ Kentucky|\ Louisiana|\ Massachusetts|\ Maryland|\ Maine|\ Marshall Islands|\ Michigan|\ Minnesota|\ Missouri|\ Marianas|\ Mississippi|\ Montana|\ North Carolina|\ North Dakota|\ Nebraska|\ New Hampshire|\ New Jersey|\ New Mexico|\ Nevada|\ New York|\ Ohio|\ Oklahoma|\ Oregon|\ Pennsylvania|\ Puerto Rico|\ Rhode Island|\ South Carolina|\ South Dakota|\ Tennessee|\ Texas|\ Utah|\ Virginia|\ Virgin Islands|\ Vermont|\ Washington|\ Wisconsin|\ West Virginia|\ Wyoming|\ CANADA|\ Alberta|\ Manitoba|\ Alberta|\ British Columbia|\ Manitoba|\ New Brunswick|\ Newfoundland and Labrador|\ Nova Scotia|\ Northwest Territories|\ Nunavut|\ Ontario|\ Prince Edward Island|\ Quebec|\ Saskatchewan|\ Yukon Territory|\ UNITED KINGDOM|\ Avon|\ Bedfordshire|\ Berkshire|\ Buckinghamshire|\ Cambridgeshire|\ Cheshire|\ Cleveland|\ Cornwall|\ Cumbria|\ Derbyshire|\ Devon|\ Dorset|\ Durham|\ Essex|\ Gloucestershire|\ Greater London|\ Greater Manchester|\ Hampshire|\ Hereford & Worcestershire|\ Hertfordshire|\ Humberside|\ Isle of Man|\ Isle of Wight|\ Kent|\ Lancashire|\ Leicestershire|\ Lincolnshire|\ Merseyside|\ Norfolk|\ Northamptonshire|\ Northumberland|\ Nottinghamshire|\ Oxfordshire|\ Shropshire|\ Somerset|\ Staffordshire|\ Suffolk|\ Surrey|\ Sussex|\ Warwickshire|\ West Midlands|\ Wiltshire|\ Yorkshire|\ '; Quote Link to comment https://forums.phpfreaks.com/topic/62738-trouble-with-a-for-loop/ Share on other sites More sharing options...
dbillings Posted July 31, 2007 Share Posted July 31, 2007 This works. You didn't include <select> perhaps? And possibly even <form>? <?php $state = '\ UNITED STATES|\ Alaska|\ Alabama|\ Arkansas|\ American Samoa|\ Arizona|\ California|\ Colorado|\ Connecticut|\ D.C.|\ Delaware|\ Florida|\ Georgia|\ Hawaii|\ Iowa|\ Idaho|\ Illinois|\ Indiana|\ Kansas|\ Kentucky|\ Louisiana|\ Massachusetts|\ Maryland|\ Maine|\ Marshall Islands|\ Michigan|\ Minnesota|\ Missouri|\ Marianas|\ Mississippi|\ Montana|\ North Carolina|\ North Dakota|\ Nebraska|\ New Hampshire|\ New Jersey|\ New Mexico|\ Nevada|\ New York|\ Ohio|\ Oklahoma|\ Oregon|\ Pennsylvania|\ Puerto Rico|\ Rhode Island|\ South Carolina|\ South Dakota|\ Tennessee|\ Texas|\ Utah|\ Virginia|\ Virgin Islands|\ Vermont|\ Washington|\ Wisconsin|\ West Virginia|\ Wyoming|\ CANADA|\ Alberta|\ Manitoba|\ Alberta|\ British Columbia|\ Manitoba|\ New Brunswick|\ Newfoundland and Labrador|\ Nova Scotia|\ Northwest Territories|\ Nunavut|\ Ontario|\ Prince Edward Island|\ Quebec|\ Saskatchewan|\ Yukon Territory|\ UNITED KINGDOM|\ Avon|\ Bedfordshire|\ Berkshire|\ Buckinghamshire|\ Cambridgeshire|\ Cheshire|\ Cleveland|\ Cornwall|\ Cumbria|\ Derbyshire|\ Devon|\ Dorset|\ Durham|\ Essex|\ Gloucestershire|\ Greater London|\ Greater Manchester|\ Hampshire|\ Hereford & Worcestershire|\ Hertfordshire|\ Humberside|\ Isle of Man|\ Isle of Wight|\ Kent|\ Lancashire|\ Leicestershire|\ Lincolnshire|\ Merseyside|\ Norfolk|\ Northamptonshire|\ Northumberland|\ Nottinghamshire|\ Oxfordshire|\ Shropshire|\ Somerset|\ Staffordshire|\ Suffolk|\ Surrey|\ Sussex|\ Warwickshire|\ West Midlands|\ Wiltshire|\ Yorkshire|\ '; ?> <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <select name="state"> <?php $state_arr = explode("|", $state); for ($i=0; $i < (count($state_arr)); $i++) { echo "<option value='" . $state_arr[$i] . "'>" . $state_arr[$i] . "</option>"; } ?> </select> </form> Quote Link to comment https://forums.phpfreaks.com/topic/62738-trouble-with-a-for-loop/#findComment-312256 Share on other sites More sharing options...
horseatingweeds Posted July 31, 2007 Author Share Posted July 31, 2007 Oh-ggggs. If I keep this up, you guys are going to start ignoring my questions. Thanks for pointing that out to me. Quote Link to comment https://forums.phpfreaks.com/topic/62738-trouble-with-a-for-loop/#findComment-312268 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.