【问题标题】:How can I add a search bar to search text on .html page [closed]如何添加搜索栏以搜索 .html 页面上的文本 [关闭]
【发布时间】:2015-04-12 21:32:16
【问题描述】:

我知道我可以添加这个:

<form>
  Search Google:
  <input type="search" name="googlesearch">
</form>

但这只会让我搜索谷歌。

我希望人们能够在此列表中搜索名称。 http://graphicambi.tk/onlineemployees.html

我该怎么做?

还有

我不知道该放在哪里 太……

这是我的代码的一部分:

    } 

$sql = "SELECT userID, users_name, usertype, status FROM tbluseraccounts";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    if($row["status"] == "Online"){
        $tcolor = "green";
    }
    elseif($row["status"] == "Offline"){
        $tcolor = "red";
    }
        echo "<br>ID: " . $row["userID"]. " <br> Name: " . $row["users_name"]. " <br> Account Type: " . $row["usertype"]. " <br> Status: <font color='".$tcolor."'>" . $row["status"]. "</font><br>";
     }
} else {
     echo "0 results";
}

在哪里说:

echo "<br>ID: " . $row["userID"]. " <br> Name: " . $row["users_name"]. " <br> Account Type: " . $row["usertype"]. " <br> Status: <font color='".$tcolor."'>" . $row["status"]. "</font><br>";

我想在那里创建边框,所以当您访问此网站时http://graphicambi.tk/onlineemployees.html 每个帐户名称周围都会有一个黑色边框

谢谢。

【问题讨论】:

  • 你知道他们可以使用浏览器的 ctrl+f 查找
  • 是的。只是想 id 尽量让他们更容易哈哈。

标签: php html list search


【解决方案1】:

我认为您的订单在数据库中,因此您可以使用简单的搜索表单。

类似这样的:

<FORM method="POST" action="search.php">
    <INPUT type="text" name="search">
    <INPUT type="submit">
</FORM>

在你的 search.php 文件中:

$sql = "SELECT userID, users_name, usertype, status FROM tbluseraccounts WHERE users_name LIKE %$_POST['search']%";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    if($row["status"] == "Online"){
        $tcolor = "green";
    }
    elseif($row["status"] == "Offline"){
        $tcolor = "red";
    }
        echo "<br>ID: " . $row["userID"]. " <br> Name: " . $row["users_name"]. " <br> Account Type: " . $row["usertype"]. " <br> Status: <font color='".$tcolor."'>" . $row["status"]. "</font><br>";
     }
} else {
     echo "0 results";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多