PHP |从过滤器到搜索?

时间:2018-06-11 16:25:09

标签: php search web

我想进行PHP搜索,但我的代码就像过滤器一样。 我该如何更改/修复它?

<div class="block-header">
	
    <form action="index.php" method="get">
	<input type="text" name="spieler" placeholder="...">
	<button class="los" name="search" type="submit"><i class="fas fa-search"></i> Suche</button>
					
	<h2>
 
    <?php while($row = mysqli_fetch_array($search_result)):?>
	<tr>
	    <td><a style="font-weight:none;">Name:</a> <?php echo $row['Name'];?></td>
	    <td>| <a style="font-weight:none;">Kills:</a> <?php echo $row['Kills'];?></td>
	    <td>| <a style="font-weight:none;">Deaths:</a> <?php echo $row['Deaths'];?><br></td>
	</tr>
    <?php endwhile;?>
	</h2>
	</form>
						
</div>

1 个答案:

答案 0 :(得分:0)

使用Connection连接代码的其余部分。

<?php include 'util/db.php'; 

    if(isset($_GET['search']))
    {
        $spieler = $_GET['spieler'];
        // search in all table columns
        // using concat mysql function
        $query = "SELECT * FROM `skypvp` WHERE CONCAT(`name`) LIKE '%".$spieler."%'";
        $search_result = filterTable($query);
        
    }
     else {
        $query = "SELECT * FROM `skypvp`";
        $search_result = filterTable($query);
    }

    // function to connect and execute the query
    function filterTable($query)
    {
        $connect = mysqli_connect("XXX", "XXX", "XXX", "XXX");
        $filter_Result = mysqli_query($connect, $query);
        return $filter_Result;
    }
    ?>