PHP - 如何向现有搜索结果添加过滤器

Background: I currently have a set up where people are dropped in page where they have BB Cards they don't own. I want them to be able to filter out the EXISTING list to narrow it down...

How do I add a filter with PHP to that EXISTING search result so they can break it down? Here is my existing relevant code:

<div id="col2"><br><br><center>Your Baseball Cards<center><br><br><br>
<?php
$servername = "********";
$username = "******";
$password = "*******";
$dbname = "*******";
$username1=$_SESSION['activeusername'];
    $userid = $_SESSION['activeid'];
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT * FROM useritems JOIN (users, iteminfo) on (users.id=useritems.UserID AND iteminfo.ID=useritems.ItemID) AND userid!='$userid' LIMIT 100";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "<a href='iteminfo.php?id=". $row['id']."'><div id='frame'>
<div id='splash-image' style='background: url(".$row['imagename']."); background-size:cover;'></div>
<div id='text'>
<table >
<tr>
    <td>Player:</td>
    <td>".$row["player"]."</td>
</tr>
<tr>
    <td>Brand:</td>
    <td>".$row["brand"]."</td>
</tr>
<tr>
    <td>Year:</td>
    <td>".$row["year"]."</td>
</tr>
<tr>
    <td>Price:</td>
    <td>".$row['price']."</td>
</tr>
</table>
</div>
</div>";
    }
} else {
    echo "You Have No Baseball Cards!!!";
}

mysqli_close($conn);
?>
</div>

<div id="col3">column 3</div>

<div id="footer">footer</div>

</body>
</head>
<html> 

I'm not exactly sure what you want by filtering, but I assume you mean that the user can filter based on Player, Brand, Year, etc. If that's the case, then you can add a WHERE clause to your SQL statement.

Here is an example using filtering by player (assuming you have an element and a form to submit.

$where_clause = "AND player='" . filter_var($_POST['player'], FILTER_SANITIZE_STRING) . "'";

$sql = "SELECT * FROM useritems JOIN 
(users, iteminfo) ON (users.id=useritems.UserID AND iteminfo.ID=useritems.ItemID)
WHERE userid != '$userid' $where_clause LIMIT 100";

If you want, you can do this in a loop with multiple inputs, appending to the WHERE clause any additional filters the user entered.