使用 PHP 和 MySQL 隐藏包含特定字符串的行

Hide Rows That Contain A Certain String Using PHP and MySQL

我有这个 PHP 代码块,它从数据库中提取信息。

我只想 filter/hide 具有 "Player" 的行,例如 "string"。

    <?php
    while ($row = mysql_fetch_assoc($result))
    {
        echo "<tr>";

        echo "<td>";
        echo $row["player"];
        echo "</td>";

        echo "<td>";
        echo $row["by"];
        echo "</td>";

        echo "</tr>";
    }
    ?>

例如,我会在下面有一个 table:

我希望它看起来像下面的 table:

使用 strpos() 你可以检查 if (strpos($row["player"], 'String') === false) 并且只有 echo 如果 true

<?php
while ($row = mysql_fetch_assoc($result))
{

  if (strpos($row["player"], 'String') === false){

    echo "<tr>";

    echo "<td>";
    echo $row["player"];
    echo "</td>";

    echo "<td>";
    echo $row["by"];
    echo "</td>";

    echo "</tr>";

  }
}
?>

根据@Fred-ii 的评论-
如果你有可能 string vs String,你可以使用 stripos() 而不是 strpos()

if (stripos($row["player"], 'string') === false)

编辑
根据@Fred-ii 的第一条评论,您还可以在查询中过滤掉它们,因此您不必在 php 代码中 'hide' 它们。

SELECT ... FROM ... WHERE player NOT LIKE 'String%'