0
$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 ですべての結果を取得します。または、somebode 検索のみ .exe get all results with type.exe $where .= " title, typeLIKE '%$keyword%'";//I did it like this no result $where .= " titleAND typeLIKE '%$keyword%'" ;//I did it like this no result $where .= " titleLIKE '%$keyword%' AND typeLIKE '%$keyword%'";// I did it like this no result 誰かが私の結果を得る方法を知っている記号「.」付きのタイトルタイプで???

4

2 に答える 2

2
$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%'";
}
于 2013-01-31T07:08:32.960 に答える
1
$where .= "`title` LIKE '%$keyword%' OR type LIKE '%$type%'";
于 2013-01-31T07:32:37.513 に答える