title: chained selects with one table
body: <p>I know I am going about this in an unusual way, every tut I've seen uses multiple tables, but due to the way the rest of my site works I would like to create a chained select which operates using a single table.</p>
  
  <p>My table structure is:</p>
  
  <pre><code>----------------------
  |Catagory|SubCategory|
  |01|cat1 |subcat1    |
  |02|cat1 |subcat2    |
  |03|cat2 |subcat1    |
  |04|cat2 |subcat2    |
  ----------------------
  </code></pre>
  
  <p>The code I have so far looks like:</p>
  
  <pre><code>&lt;tr&gt;
      &lt;td class="shadow"&gt;&lt;strong&gt;Category:&lt;/strong&gt;   &lt;/td&gt;
      &lt;td class="shadow"&gt;
      &lt;select id="category" name="category" style="width:150px"&gt;
          &lt;option selected="selected" value="&lt;?php echo $category ?&gt;"&gt;&lt;?php echo $category?&gt;&lt;/option&gt;
          &lt;?php
          include('connect.php');
          $result1 = mysql_query("SELECT DISTINCT category FROM categories")  
              or die(mysql_error());  
  
              while($row = mysql_fetch_array( $result1 )) {
              $category = $row['category'];
              echo "&lt;option value='". $row['category'] ."'&gt;". $row['category'] ."&lt;/option&gt;";
              }
          ?&gt;        
      &lt;/select&gt;
     &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td class="shadow"&gt;&lt;strong&gt;Sub Category:&lt;/strong&gt;   &lt;/td&gt;
      &lt;td class="shadow"&gt;
      &lt;select id="sub_catgory" name="sub_category" style="width:150px;"&gt;
          &lt;option selected="selected" value="&lt;?php echo $sub_category ?&gt;"&gt;&lt;?php echo $sub_category ?&gt;&lt;/option&gt;
          &lt;?php
              include('connect.php');
              $result2 = mysql_query("SELECT sub_category FROM categories WHERE ")
                  or die(mysql_error());
  
                  while($row = mysql_fetch_array ($result2 )){
                  echo "&lt;option value='" . $row['sub_category'] . "'&gt;". $row['sub_category']. "&lt;/option&gt;";
          }
  
          ?&gt;    
      &lt;/select&gt;
      &lt;/td&gt;           
  &lt;/tr&gt;
  </code></pre>
  
  <p>On the second select I am not sure how to state the WHERE clause. I need it to display the subcategories which have the same category as selected in the first select. </p>
  
  <p>PART 2 how would I include AJAX in this to preload the data so i don't need to refresh the page.</p>
  
  <p>Could someone either help me finish what I've started here or point me to a good tutorial.</p>
  
  <p>thanks</p>