duanqiaoren9975 2015-05-07 06:46
浏览 60
已采纳

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

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>
  • 写回答

1条回答 默认 最新

  • duanbushi1479 2015-05-07 10:58
    关注

    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()
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!