搜索多个词 PHP mysqli

Search for multiple words PHP mysqli

我有一个简单的搜索 PHP 脚本,但它只能这样工作:

示例: 我在数据库“dvd-creator-setup”中有,但如果我想找到它,我需要写下整个字符串,比如“dvd”或“dvd-creator”。 是否可以使其适用于“dvd creator”或“creator setup”之类的查询?

if (isset($_POST['searchh'])) {
        $searchValue = $_POST['search'];
        if ($conn->connect_error) {
            echo "connection Failed: " . $conn->connect_error;
        } else {
            $sql = "SELECT * FROM pubfiles WHERE filename LIKE '%$searchValue%'";

            $result = $conn->query($sql);
            while ($row = $result->fetch_assoc()) {
              echo "File name: <a href=".$row["path"].">" . $row["filename"]. "</a><br />Size: " . $row["size"]. " MB<br/> Uploaded by: " . $row["uploaded_by"]. "<br>-----------------<br>";

            }


        }

您可以在 filename 列上使用全文索引。

alter table pubfiles add fulltext(filename);

这允许您使用 MATCH() ... AGAINST 语法查询文件名列。

select * from pubfiles where match(filename) against ('dvd creator');

这会找到 'dvd', 'dvd-creator', 'dvd-creator-setup' , 'creator'.

还有一个 BOOLEAN MODE,可让您根据需要标记所有单词。

select * from pubfiles
  where match(filename) against ('+dvd +creator' IN BOOLEAN MODE);

那只会 return 'dvd-creator''dvd-creator-setup'.