/ Published in: PHP
This snippet will allow you to dynamically create a form dropdown list of all of the states within the US, Canada and UK. It pulls them from a table called state in a database. This snippet is used in conjunction with http://snipplr.com/view/36725/stateprovince-for-united-states-canada-and-uk/ which will actually create the state table within your database. The dropdown list is sorted by the state_id so all US states are listed together, all CA provinces are listed together and the same for the UK.
Expand |
Embed | Plain Text
$sql = "select state_id,state_name,state_abbr from state order by state_id"; } print '<select name="state"><br>\n'; print '<option value=""> - Select State/Province - '; $state_id = $row[0]; $state_name = $row[1]; $state_abbr = $row[2]; print "<option value=\"$state_abbr\""; print "> $state_name <br>\n"; } print '</select>';
You need to login to post a comment.
