2015-06-18 68 views
1

我有一個配方表,包含id,recipe_name,recipe_ingredients字段。我加入這些表爲了搜索特定配方。如何使用LIKE進行搜索,包括空格和唯一空格?

我的問題:「我怎麼可以搜索貼貼面,方便麪條等只用‘像查詢麪條’

我的查詢:

SELECT r.*,l.*,CASE WHEN (COUNT(l.recipe_id)=0)THEN 0 ELSE 1 END as like_status, 
    u.name,u.user_image,u.location,u.contact_no,COUNT(l.recipe_id) as total_likes 
FROM recipe as r 
    LEFT JOIN likes as l ON r.recipe_id = l.recipe_id 
    LEFT JOIN user_detail as u ON r.user_id = u.user_id 
WHERE r.recipe_name LIKE '%$search%' 

以上礦井的查詢返回包含數據「麪條」。我曾嘗試更換使用上面的查詢替換空間,但不是luck.So我怎麼能搜索使用LIKE包括所有的空格和空格?

+0

它不關心空白。你確定它不是區分大小寫嗎? 'LOWER(r.recipe_name)'如'%$ search%'' –

回答

0

我們可以利用這樣的

select * from table_name where table_name like "%Veg Noodles%" 

這些SQL對我來說很有用

謝謝。