【发布时间】:2021-10-07 03:46:31
【问题描述】:
嘿,我有一个由 PHP while 循环创建的 HTML 表。为此,我想要一个可以搜索表格的输入。我在互联网上找到的普通 JavaScript 版本不起作用。我认为这是因为该表不在 HTML 源代码中,而是由 PHP 插入的。感谢您的任何回答,祝您有愉快的一天!
<table class="table" id="searchtable">
<thead>
<tr>
<th scope="col">Username</th>
<th scope="col">Rank</th>
</tr>
</thead>
<tbody>
<?php
require $_SERVER['DOCUMENT_ROOT'].'/req/config.php';
$stmt = $sql->prepare("SELECT * FROM users");
$stmt->execute();
while ($result = $stmt->fetch()) {
?>
<tr>
<th scope="row"><?php echo $result["username"] ?></th>
<th><?php echo $result["rank"] ?></th>
</tr>
<?php
}
?>
</tbody>
</table>
【问题讨论】:
-
你想要的搜索和过滤应该通过SQL语句来完成,
$stmt = $sql->prepare("SELECT * FROM users WHERE `username`='bob'"); -
这个问题你到底需要什么?您需要只获取行还是需要获取整个表?
标签: javascript php html search filter