为我的多个下拉列表创建动态按钮

时间:2017-04-25 18:29:37

标签: php jquery

我创建了一个动态下拉列表,它们在Comugg.com上相互依赖。继承人的代码。

    function dropdownmenu() { 
include_once "connection.php";
?>
    <div class="make">
    <label>Make</label>
        <select name="make" id="makelist" onchange="getId(this.value);">
            <option value="">Select Make</option>

        <?php       
        $query = "select distinct(Make) from websitemasterlist order by Make ASC";
        $results = mysqli_query($conn, $query);

        foreach($results as $info) {
        ?>
            <option value="<?php echo $info[Make]; ?>"><?php echo $info[Make]; ?></option>

        <?php
        }
        ?>
        </select>
    </div>

    <div id="model">
    <label>Model</label>
        <select name="model" id="modellist" onchange="getId2(this.value);">
            <option value="">Select Model</option>
        </select>
    </div>

            <div id="year">
    <label>Year</label>
        <select name="year" id="yearlist" onchange="getId3(this.value);">
            <option value="">Select Year</option>
        </select>
    </div>

    <button id="dropdownbutton" onclick="dropdownbutton()" class="vc_general vc_btn3 vc_btn3-size-md vc_btn3-shape-rounded vc_btn3-style-3d vc_btn3-color-success">Dropdown</button>


    <script>
        function getId(val){
                jQuery.ajax({
                method: "POST",
                url: "getdata.php",
                data: "make="+val,
                success:function(data){
                    jQuery("#modellist").html(data);
                }
                });


        }
        function getId2(val){
                jQuery.ajax({
                method: "POST",
                url: "getdata.php",
                data: "model="+val,
                success:function(data){
                    jQuery("#yearlist").html(data);
                }
                });

        }

        function dropdownbutton(val){
        }

    </script>
<?php
}

和继承人我的getdata.php

<?php
include_once "connection.php";
$make = $_POST["make"];
$model= $_POST["model"];


if (!empty($_POST["make"])) {
    $make = $_POST["make"];
    echo $query = "SELECT Distinct Model FROM websitemasterlist where Make='".$make."'"; 
    $results = mysqli_query($conn, $query);
    ?>
    <option value="">Select Model</option>
    <?php
    foreach ($results as $info){
    ?>
    <option value="<?php echo $info["Model"]; ?>"><?php echo $info["Model"]; ?></option>
    <?php
    }
}

if (!empty($_POST["model"])) {
    $model = $_POST["model"];
    echo $model;
    echo $query = "SELECT Distinct Year FROM websitemasterlist where Model='".$model."'"; 
    $results = mysqli_query($conn, $query);
    ?>
    <option value="">Select Year</option>
    <?php
    foreach ($results as $info){
    ?>
    <option value="<?php echo $info["Year"]; ?>"><?php echo $info["Year"]; ?></option>
    <?php
    }
}
?>

我试图找出如何创建动态链接。例如,我想做这样的事情,但我不确定如何从每个字段中获取选定的值。

<a href="http://comugg.com/category/<?php echo $year; ?>/<?php echo $make; ?>/<?php echo $model; ?>>text</a>

我应该怎么做?

0 个答案:

没有答案