我想構建一個頁面,顯示在html表格中搜索到的數據。我在頁面上設置了搜索字段和按鈕,並在當前顯示了所有數據的小型表格中。我需要它根據搜索字段中的詞主動更改表中顯示的數據。如何根據搜索結果動態更改表格中的數據?
編輯:
我怎麼能動態地根據在搜索字段中的文本改變表中的數據?
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT clientname, clientsurname, address1, postcode, dob FROM clients";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>Name</th><th>Surname</th><th>Address</th><th>Postcode</th><th>Date of Birth</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["clientname"]."</td><td>".$row["clientsurname"]."</td><td>".$row["address1"]."</td><td>".$row["postcode"]."</td><td>".$row["dob"]."</td></tr>";
}
echo "</table>";
} else {
echo "There are 0 clients in the system matching your search criteria";
}
$conn->close();
?>
你有queston? – Naruto
抱歉,我忘了添加最後一行,現在編輯帖子並更新。不便之處 – DGTLSS
看看ajax和jquery .. – Naruto