gpt4 book ai didi

php - 如何查询 SELECT name FROM movie WHERE Category LIKE :search - with adding some string before and after SEARCH

转载 作者:行者123 更新时间:2023-11-29 11:40:28 27 4
gpt4 key购买 nike

我有疑问:

SELECT name FROM movies WHERE category LIKE :search

我在列类别中有多个 ID:1,81,23为了更好地搜索,需要在查询中的 :search 的开头和结尾添加逗号,例如 ',1,81,23,' 以搜索模式 ',XX,' 中的特定 id

$stmt = $this->db->prepare('SELECT name FROM movies WHERE category LIKE :search');
$stmt->bindValue(':search', "%$search%", PDO::PARAM_STR);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);

需要查找单个ID

最佳答案

SELECT DISTINCT b.name
FROM(
SELECT 'searchString' AS Keyword
FROM movies
) AS a
INNER JOIN movies AS b
ON a.Keyword like '%'+b.category+'%'

将您的用户输入放入“searchString”中,就可以了。当输入',1,18,23,'时,会显示3条记录。

关于php - 如何查询 SELECT name FROM movie WHERE Category LIKE :search - with adding some string before and after SEARCH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35858095/

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