2016-03-08 66 views
0

之後加入一些字符串我有查詢:如何查詢SELECT名字從電影WHERE類,如:搜索 - 之前和搜索

SELECT name FROM movies WHERE category LIKE :search 

我在列類別的多個ID:1,81,23 爲了更好的搜索要在開頭和結尾添加逗號:在查詢搜索要像「 1,81,23,」在模式搜索特定ID「 XX,」

$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

回答

1
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'時,它會顯示三條記錄。