$where = "";
$keywords =preg_split('/[\s]+/', $keywords);
$total_keywords = count($keywords);

foreach($keywords as $key=>$keyword) {
    $where .= "`title` LIKE '%$keyword%'";
    if ($key != ($total_keywords - 1)) {
        $where .= " AND ";
    }
}

    $results = "SELECT `id`, `username`, `title`, LEFT(`description`, 90) as `description`, `file`, `code`, `type`, `size`, `date` FROM `files` WHERE $where ORDER BY id DESC LIMIT $start, $per_page";


  $where .= "`title` LIKE '%$keyword%'"; // this case I am searching only in column `title` I want to search too in column `type` with sign '.' I don't know how to include '.' in search result for `type`


示例搜索file.exe,并使用此条件file.exe获取所有结果。或仅搜索.exe使用type .exe获取所有结果
      $ where。=“” titletype就像'%$ keyword%'“; //我没有这样做
      $ where。=“” titletype像'%$ keyword%'“; ///我这样做像这样,没有结果
      $ where。=“” title象'%$ keyword%'AND type象'%$ keyword%'“; //我没有这样做
有人知道如何获得带有标题“。”的标题类型的结果。

最佳答案

$where .= "`title` LIKE '%$keyword%' OR type LIKE '$type'";


更新的代码

$pos = strpos($keyword, '.');
if($pos > 0) {
    $parts = explode('.', $keyword);
    $type = array_pop($parts);
    $file = array_pop($parts);
    $where .= "`title` LIKE '%$file%' AND type LIKE '%$type%'";
}
else {
$where .= "`title` LIKE '%$keyword%' OR type LIKE '%$type%'";
}

09-05 17:30
查看更多