0

我找到了一个链接下拉框的示例,但是我正在努力确保第三个框使用前面的两个框来显示所需的结果。

这些框旨在显示以下内容,

下拉框 1 = 选择一个部门

下拉框 2 = 选择一个级别

下拉框 3 = 选择资格

On the last SQL query i have shown a $HELP, i think this is where im having my problems, i think it is loosing the previously stored value in dropdown box 1 when dropdown box 2 is selected.

<?php
//**************************************
//     Page load dropdown results     //
//**************************************
function getTierOne()
{
    $result = mysql_query("SELECT DISTINCT SSA1Text FROM qualifications ORDER BY SSA1Text ASC") 
    or die(mysql_error());

      while($tier = mysql_fetch_array( $result )) 

        {
           echo '<option value="'.$tier['SSA1Text'].'">'.$tier['SSA1Text'].'</option>';
        }

}

//**************************************
//     First selection results     //
//**************************************
if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 
   drop_1($_GET['drop_var']); 
}

function drop_1($drop_var)
{  
    include_once('db.php');
    $result = mysql_query("SELECT DISTINCT Level FROM qualifications WHERE SSA1Text='$drop_var' ORDER BY Level ASC") 
    or die(mysql_error());

    echo '<select name="drop_2" id="drop_2">
          <option value=" " disabled="disabled" selected="selected">Choose one</option>';

           while($drop_2 = mysql_fetch_array( $result )) 
            {
              echo '<option value="'.$drop_2['Level'].'">'.$drop_2['Level'].'</option>';
            }

    echo '</select>';
    echo "<script type=\"text/javascript\">
    $('#wait_2').hide();
    $('#drop_2').change(function(){

      $('#wait_2').show();
      $('#result_2').hide();
      $.get(\"func.php\", {
        func: \"drop_2\",
        drop_var: $('#drop_2').val()
      }, function(response){
        $('#result_2').fadeOut();
        setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
      });
        return false;
    });
</script>";
}


{//**************************************
//     Second selection results     //
//**************************************
if($_GET['func'] == "drop_2" && isset($_GET['func'])) { 
   drop_2($_GET['drop_var']); 
}

function drop_2($drop_var)
{  
    include_once('db.php');
    $result = mysql_query("SELECT * FROM qualifications WHERE Level='$drop_var' AND SSA1Text='$HELP'") 
    or die(mysql_error());

    echo '<select name="drop_3" id="drop_3">
          <option value=" " disabled="disabled" selected="selected">Choose one</option>';

           while($drop_3 = mysql_fetch_array( $result )) 
            {
              echo '<option value="'.$drop_3['Title'].'">'.$drop_3['Title'].'</option>';
            }

    echo '</select> ';
    echo '<input type="submit" name="submit" value="Submit" />';
}
?>

任何帮助将非常感激。

4

1 回答 1

0

您可以将两个选择变量都传递给 drop_2 函数吗?

function drop_2($drop_var1, $drop_var2 == null) {
    if ($drop_var2 !== null) {
        $sqlSnipet = " AND SSA1Text='$drop_var2'"
    }
    $result =
        mysql_query(
            "SELECT * 
            FROM qualifications 
            WHERE Level='$drop_var' " .
            $sqlSnipet
        ) or die(mysql_error());
}
于 2013-05-30T15:22:27.633 回答