首页 > 解决方案 > 如何用结果填充 HTML 表格并过滤它们

问题描述

到目前为止,这是我的代码。我试图通过 html 在表中显示我的数据库的一个表。然后我希望能够使用关键字过滤这些结果,但是,此时结果甚至没有显示,我不确定为什么?所有代码目前都在一个文件中,calendar.php

<?php
session_start();

if(isset($_POST['search'])) {

}else {
  $query = "SELECT * FROM knockout"; //selecting all results in table and filtering
  $search = filterTable($query);
}

function filterTable($query){
  include_once "action/dbcon.php";
  $filter = mysqli_query($conn, $query);
  return $filter;
}
?>

    <form>
    <input type=text name="valueToSearch" placeholder="Search">
    <input type=submit name="search" value="filter">

    <table>
      <tr>
        <th>Id:</th>
        <th>Team 1:</th>
        <th>Team 2:</th>
        <th>Date::</th>
      </tr>
    </table>
    <?php while($row = mysqli_fetch_array($search)); ?>
      <tr>
        <td><?php echo $row['knockout_id']; ?></td>
        <td><?php echo $row['knockout_team1']; ?></td>
        <td><?php echo $row['knockout_team2']; ?></td>
        <td><?php echo $row['knockout_date']; ?></td>
      </tr>
    <?php endwhile;?>
  </form>

标签: phphtmlselectfilterhtml-table

解决方案


推荐阅读