下拉排序(过滤器)不起作用

时间:2016-03-21 12:51:33

标签: javascript php jquery

我创建了一个详细信息页面,人们可以使用下拉菜单过滤数据库中的所有内容,但这不起作用

function.js:

<script>
function showUser(str) {
if (str == "") {
    document.getElementById("txtHint").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("txtHint").innerHTML = xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET","admin2.php?q="+str,true);
    xmlhttp.send();
}
}
</script>

这是我的下拉菜单:

<?php

$servername = "localhost";
$username = "root";
$password = "usbw";
$dbname = "persons";

// CREATE A CONNECTION WITH THE DATABASE
// CONNECTIE MAKEN MET DATABASE
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

//$sql="SELECT name,id FROM student"; 

$sql="SELECT DISTINCT address_state FROM address ORDER BY address_state asc"; 

/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */

echo '<select name="users" onchange="showUser(this.value)">'; // list box select command

foreach ($conn->query($sql) as $row){//Array or records stored in $row

echo '<option value="'.$row[address_state].'">'.$row[address_state].'</option>';  

/* Option values are added by looping through the array */ 

}

echo "</select>";// Closing of list box
?>

这是我的表格部分:

<?php

$servername = "localhost";
$username = "root";
$password = "usbw";
$dbname = "persons";

// CREATE A CONNECTION WITH THE DATABASE
// CONNECTIE MAKEN MET DATABASE
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

// SELECT TABLE NAMES FROM PERSON, ADDRESS AND CV WHERE address_id IS person_address and cv_id IS person_cv
// SELECTEER VAN TABEL PERSON, ADDRESS AND CV WAAR address_id  GELIJK IS AAN person_address EN cv_id AAN person_cv
$sql = "SELECT person_id, person_firstname, person_lastname, 
                 person_email, person_phonenumber,  
                 address_street,address_housenumber, 
                 address_city,address_state,address_zipcode, cv_path
          FROM person 
            inner join address on address.address_id = person.person_address 
            inner join cv on cv.cv_id = person.person_cv";

// EXECUTE QUERY IF THE RESULT BIGGER IS THAN ZERO
// VOER QUERY UIT ALS RESULTAAT GROTER IS DAN NUL
$result = $conn->query($sql);
if ($result->num_rows > 0) {

// ECHO A TABLE WITH VALUES 
// ECHO EEN TABEL MET ONDERSTAANDE WAARDES
echo "<div id='txtHint'>";
echo "<form action='admin.php' method='post'>"; 
echo "<table border=0 align=right>
<tr>
<th>Voornaam</th>
<th>Achternaam</th>
<th>Straat</th>
<th>Huisnummer</th>
<th>Postcode</th>
<th>Stad</th>
<th>Provincie</th>
<th>Email</th>
<th>Mobiel</th>
<th>cv</th>
<th>delete</th>
</tr>";

// LOOP THROUGH THE RESULTS AND OUTPUT THE RESULTS FOR EACH ROW
// GA DOOR RESULTATEN EN LAAT DE RESULTEN PER RIJ ZIEN
while($row = $result->fetch_assoc()) {
     echo "<tr>";
     echo "<td>" . $row["person_firstname"] . "</td>";
     echo "<td>" . $row["person_lastname"] . "</td>";
     echo "<td>" . $row["address_street"] . "</td>";
     echo "<td>" . $row["address_housenumber"] . "</td>";
     echo "<td>" . $row["address_zipcode"] . "</td>";
     echo "<td>" . $row["address_city"] . "</td>";
     echo "<td>" . $row["address_state"] . "</td>";
     echo "<td>" . $row["person_email"] . "</td>";
     echo "<td>" . $row["person_phonenumber"] . "</td>";

    $path = "http://localhost:8080/website/" . $row['cv_path'];
    if(!empty($row['cv_path']) && file_exists($path)){
    echo "<td><a href='$path'>cv file</a></td>";
    }
    else{
    echo "<td>No Resume</td>";
    }

     echo "<td><a href='delete.php?person_id=" . $row['person_id'] . "'>delete</a></td>";
     echo "</tr>";
  }
  echo "</table>";
  echo "</form>";
  echo "<div>";
}

// IF THERE IS ZERO RESULT ECHO THIS
// ALS WAARDE NUL IS LAAT DE ONDERSTAADE TEKST ZIEN
else {
    echo "<p id='Tekst'>Er zijn geen deelnemers in de database gevonden </p>";
}
// CLOSE CONNECTION
// SLUIT CONNECTIE
$conn->close();
?>  

我真的不知道我做错了什么我尝试了很多东西但是没有成功,所以我希望你们可以帮助我。再次:dropmenu必须按所选值过滤和显示信息。我的数据库中有三个名为person,address和cv的表...我的下拉菜单是从address_state获取其值。因此,在选择州时,应显示所有人及其简历(简历pdf文件)。

0 个答案:

没有答案