【发布时间】:2015-06-21 02:19:33
【问题描述】:
我正在尝试构建一个显示已在 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();
?>
【问题讨论】:
-
你有问题吗?
-
对不起,我忘了添加最后一行,现在将编辑帖子并更新。很抱歉给您带来不便
-
看看ajax和jquery..
-
先看看MVC模式,以后会省很多时间