while 循环创建的过滤器 PHP Table

Filter PHP Table created by while loop

嘿,我有一个 HTML table,它是由 PHP while 循环创建的。为此,我想要一个可以搜索 table 的输入。我在互联网上找到的正常 JavaScript 版本不起作用。我认为这是因为 table 不在 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>

对于浏览器而言,table 是由 PHP 创建的还是手动创建的没有区别。您可能只是错误地使用了您找到的“javascript 版本”。你可以仔细尝试实现这个example of code