webguync Posted April 9, 2008 Share Posted April 9, 2008 The title is a bit convoluted. I wasn't sure how to word this, but here is what I am trying to do. In a form field a user selects a state (for instance Florida) and based upon this choice another select group appears with subcategories of the cities within that state (for instance Miami, Tampa, Ft. Lauderdale, Orlando etc.) these selected values will be stored in a database. Is this done by creating two MySQL tables and storing the values in those tables and setting a SQL trigger to display the subcategories or is there another way? I am confused as to how to start on this one so any assistance is appreciated. Link to comment https://forums.phpfreaks.com/topic/100239-subcategories-in-a-form-display-based-on-action/ Share on other sites More sharing options...
Caesar Posted April 9, 2008 Share Posted April 9, 2008 If I understood you correctly...maybe something like... <?php if(isset($_POST['state']) && $_POST['state'] != '') { $query = $DB->query("SELECT `name` FROM `states_cities` WHERE `type`='city' AND `state_abbr`='FLA'"); echo'<select name="cities">'; while($row = $DB->fetch_array($query)) { echo'<option value="'.$row[1].'">'.$row[1].'</option>'; } echo'</select>'; } ?> states_cities Table.... id | name | type | state_abbr ================================================ 1 Florida state FLA 2 Miami city FLA 3 Orlando city FLA Link to comment https://forums.phpfreaks.com/topic/100239-subcategories-in-a-form-display-based-on-action/#findComment-512542 Share on other sites More sharing options...
webguync Posted April 9, 2008 Author Share Posted April 9, 2008 thanks, that gives me a start. I plan to have all 50 states though and about 5 cities per state. When a user selects the option of a certian state the cities pertaining to that state will display. Link to comment https://forums.phpfreaks.com/topic/100239-subcategories-in-a-form-display-based-on-action/#findComment-512587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.