gpt4 book ai didi

从 2 列中搜索 php mysql

转载 作者:太空宇宙 更新时间:2023-11-03 12:32:43 25 4
gpt4 key购买 nike

$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 search only .exe 使用 type .exe 获取所有结果 $where .= "title, type LIKE '%$keyword%'";//我这样做没有结果 $where .= "title AND type LIKE '%$keyword%'";//我这样做没有结果 $where .= "title LIKE '%$keyword%' AND type LIKE '%$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%'";
}

关于从 2 列中搜索 php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14620184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com