多重选择ajax过滤数据库

时间:2016-02-07 19:24:01

标签: php jquery ajax oracle

我正在尝试使用2选择选项过滤我的数据库 我想要的是当用户加载页面时他们可以看到组织在表中的数据库结果,当他们选择select(下拉列表)表被过滤时,他们可以选择其中一个select(下拉列表)或两者为了获得最佳效果那么如何调整我的代码才能按我的意愿工作呢? 我正在使用oracle hr数据库

HTML(家):

<html>
<head>
<script>
function showInfo(str) {
    if (str == "") {
        document.getElementById("information").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("information").innerHTML = xmlhttp.responseText;
            }
        };

        xmlhttp.open("GET","emp.php?q="+str,true);
        xmlhttp.send();
    }
}

</script>
</head>
<body>


<select name="dep" onchange="showInfo(this.value)">
  <option value="">Select a Department:</option>
  <option value="90">Advertisement</option>
  <option value="60">IT</option>
  <option value="100">Finance</option>
  <option value="30">Public relations</option>
  </select>
<select name="manager" onchange="showInfo2(this.value)">
  <option value="">Select a Manager:</option>
  <option value="100">Bob</option>
  <option value="103">Lee</option>
  <option value="108">Rose</option>
  <option value="102">Lana</option>
  </select>
<br>
<div id="information"><b>Emp info will be listed here...</b></div>

</body>
</html> 

PHP(emp.php):

<html>
<body>

<?php
$q = intval($_GET['q']);

    $conn = oci_connect('hr', 'hr123', 'Glory-PC:1521/XE');
    if (!$conn) {
        $e = oci_error();
        trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }
    $stid = oci_parse($conn, "SELECT * FROM employees WHERE DEPARTMENT_ID= '".$q."' ");
                oci_execute($stid);


echo "<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>EMAIL</th>
<th>PHONE NUMBER</th>
<th>HIRE DATE</th>
</tr>";
while($row=oci_fetch_array( $stid, OCI_ASSOC+OCI_RETURN_NULLS )) {
    echo "<tr>";
    echo "<td>" . $row['FIRST_NAME'] . "</td>";
    echo "<td>" . $row['LAST_NAME'] . "</td>";
    echo "<td>" . $row['EMAIL'] . "</td>";
    echo "<td>" . $row['PHONE_NUMBER'] . "</td>";
    echo "<td>" . $row['HIRE_DATE'] . "</td>";
    echo "</tr>";
}
echo "</table>";

?>
</body>
</html>

0 个答案:

没有答案