Posted By

aeboi80 on 07/06/10


Tagged

php dropdown submit country remember


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

rhainek


PHP Dynamic Dropdown Box: Country - Remember Value On Submit


 / Published in: PHP
 

This snippet allows you to dynamically generate an HTML form drop down box which is populated by the values contained within a MySQL table called country. Use in conjunction with http://snipplr.com/view/36728/mysql-country-table-with-abbreviations-and-names/ to actually create the drop down box.

  1. $sql = "select country_name,country_abbrev from country order by country_name";
  2. if (!(@ $result = mysql_query($sql))) {
  3. print "There was an error running your query:<p>\n". $sql . "<p>\n";
  4. }
  5. print '<select name="country"><br>\n';
  6. print '<option value=""> - Select Country - ';
  7. while ($row = mysql_fetch_row($result)) {
  8. $country_name = $row[0];
  9. $country_abbrev = $row[1];
  10.  
  11. print "<option value=\"$country_abbrev\"";
  12. if ($_REQUEST["country"] == $country_abbrev) { print " selected"; }
  13. print "> $country_name <br>\n";
  14. }
  15. print '</select>';

Report this snippet  

You need to login to post a comment.