通过传递选定的下拉值获取第三个下拉列表的结果

I am showing the dropdowns based on the above selected dropdowns. I want the result in third dropdown. For that I am writing the sql query in php and writing the change event in jquery but i am unable to get the result. I am stuck up there

My jquery looks like

$(document).ready(function(){
    $("#parent_cat,#city").change(function(){
        $.get('loadlocation.php?city=' + $(this).val() , function(data) {
          $("#sub_cat").html(data);

        });
    });
});

parent_cat and city are from selected values

<label for="category">Category</label>
<select name="parent_cat" id="parent_cat">
    <?php while($row = mysql_fetch_array($query_parent)): ?>
        <option value="<?php echo $row['name']; ?>"><?php echo $row['name']; ?></option>
    <?php endwhile; ?>
</select>
<br/><br/>
<label for="city">city</label>
<select name="city" id="city">
    <?php while($row = mysql_fetch_array($query_parent1)): ?>
        <option value="<?php echo $row['city']; ?>"><?php echo $row['city']; ?></option>
    <?php endwhile; ?>
</select>
<br/><br/>

And my php file loadlocation.php is

<?php 
    include('config.php');
    $parent_cat = $_GET['parent_cat'];
    $city = $_GET['city'];
    $query = mysql_query("SELECT  table_place_detail.post_title FROM table_terms, table_place_detail, table_post_locations
    WHERE  table_place_detail.post_location_id =    table_post_locations.location_id AND  table_place_detail.default_category =  table_terms.term_id AND  table_post_locations.city =  '$city' AND table_terms.name =  '$parent_cat'");
    while($row = mysql_fetch_array($query)) {
        echo "<option value='$row[post_title]'>$row[post_title]</option>";
    }
?>

I want to fetch the values of parent_cat, city to loadlocation.php but i am not able to get those values. I want to load the two values and get the query excecuted and the values should shown in 3rd dropdown as below can any one help this issue

<label>Vendors List 1</label>
<select name="sub_cat" id="sub_cat"></select>

Two things stand out

  • You send only one value, ?city=
  • According to the manual jQuery.get(), you can send additional parameters as a plain object. This means, you don't need to build a query string, but can pass parent_cat and city separately, e.g.

    $.get("loadlocation.php",
          { parent_cat: $('#parent_cat').val(), city: $('#city').val() },
          function(data) {
              $('#sub_cat').html(data);
          });
    

And finally, the mandatory hint at each mysql_* page

Warning This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

  • mysqli_query()
  • PDO::query()