当我过滤我的数据库时,表是空的

时间:2018-06-13 07:06:08

标签: php mysql database filter

我试图过滤我的数据库但是当我这样做时表是空的。我从http://1bestcsharp.blogspot.com/2015/10/php-html-table-search-filter-data-mysql-database.html复制了代码。当我在test_db上尝试他的代码时,它运行良好

这是在过滤之前: https://imgur.com/a/F4J4boM

经过筛选后: https://imgur.com/a/hIFip9s

<?php

 if(isset($_POST['search']))
 {   
$valueToSearch = $_POST['valueToSearch'];
//search in all table columns
//using concat mysql function
$query = "SELECT * FROM pelajar INNER JOIN koko ON pelajar.id = koko.id WHERE 
CONCAT 
('id','nama','umur','kelasid','rsukanid','permainanid','kelabid','ppbid') 
LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else{
    $query = "SELECT * FROM pelajar INNER JOIN koko ON pelajar.id = koko.id";
    $search_result = filterTable($query);
}

//function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "pendaftaran");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}

?>

<!DOCTYPE html>
<html>
<head>
    <title>PHP HTML TABLE DATA SEARCH</title>
    <style>
        table,tr,th,td
        {
            border:1px solid black;
        }
    </style>
 </head>
 <body>
    <form action="laporan2.php"
    method="post">
        <input type="text" name="valueToSearch"
        placeholder="Value To Search"><br><br>
        <input type="submit" name="search"
        value="Filter"><br><br>

        <table>
            <tr>
    <th>Id</th>
    <th>Nama</th>
    <th>Umur</th>
    <th>Kelas</th>
    <th>Rumah Sukan</th>
    <th>Permainan</th>
    <th>Kelab</th>
    <th>Unit Beruniform</th>

            </tr>
            <!--populate table from mysql database-->
            <?php while($row = mysqli_fetch_array($search_result)):?>
            <tr>
                <td><?php echo $row['id'];?></td>
                <td><?php echo $row['nama'];?></td>
                <td><?php echo $row['umur'];?></td>
                <td><?php echo $row['kelasid'];?></td>
                <td><?php echo $row['rsukanid'];?></td>
                <td><?php echo $row['permainanid'];?></td>
                <td><?php echo $row['kelabid'];?></td>
                <td><?php echo $row['pbbid'];?></td>
            </tr>
            <?php endwhile;?>
        </table>
    </form>
    <a href="laporan2.php">
    <button
    onclick="window.print();">Cetak</button>
    </a>
 </body>
 </html>

0 个答案:

没有答案