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

报告相同问题?

悬赏问题

  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件