如何向我的表添加过滤器

时间:2016-03-04 14:59:16

标签: php jquery mysql

我想知道是否可以在我的详细信息页面中添加两个过滤器(Dropdown)。正如您在图片中看到的,我得到了一个详细信息页面,其中显示了数据库中的信息。现在我想添加两个过滤器,一个过滤stad(城市)和一个过滤器provincie(州)。

picture

下拉菜单必须按stad(city)和provincie(state)的表格行中的值添加它的值。当选择stad(city)或provincie(state)时,它只会显示居住在所选城市或州的人。

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

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 

$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";

$result = $conn->query($sql);
if ($result->num_rows > 0) {

  echo "<table border=1>
  <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>";


while($row = $result->fetch_assoc()) {
    echo "<form action=delete.php method=post>";
    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>";
    echo "<td><a href='http://localhost:8080/website/" . $row['cv_path'] . "'>cv file</a></td>";
    echo "<td>" . "<input type=submit name=delete value=delete>" . " </td>";
    echo "</tr>";
    echo "</form>";
}
}
else {
echo "Er is niks in het database gevonden";
}

$conn->close();
?>

上面的代码是显示数据库中数据并将其放入表中的代码。现在当我选择(例子)鹿特丹时,只有罗伊德应该出现在表格中。选择provincie相同...在我的数据库中,stad是address_city,provincie是address_state。我可能是错的但是有没有办法让荷兰的所有城市都有下拉菜单...所以当选择鹿特丹时它会显示Rohied但是当选择其他随机城市时它会说数据库中没有人住在选定的城市(或州)。

0 个答案:

没有答案