Jump to content

subcategories in a form display based on action


webguync

Recommended Posts

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.

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.