【问题标题】:Filter PHP Table created by while loop过滤由while循环创建的PHP表
【发布时间】: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-&gt;prepare("SELECT * FROM users WHERE `username`='bob'");
  • 这个问题你到底需要什么?您需要只获取行还是需要获取整个表?

标签: javascript php html search filter


【解决方案1】:

表格是由PHP创建的还是手动创建的,浏览器没有区别。您可以简单地错误地使用您找到的“javascript 版本”。你可以仔细尝试实现这个example of code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2021-02-20
    • 2018-05-21
    • 2015-07-16
    • 2011-06-23
    相关资源
    最近更新 更多