2012-04-09 41 views
0

如何搜索多列中的詞:titlecontent。例如:在多列中查找搜索詞

$searchTerm = 'android'; 

SELECT * FROM posts WHERE `title` OR `content` contains $SearchTerm 
+0

您可以考慮使用全文搜索對多列搜索。這將是快速.http://devzone.zend.com/26/using-mysql-full-text-searching/ – 2012-04-09 10:39:28

+0

謝謝@Pushpesh我會試一試 – Michelle 2012-04-09 12:21:39

+0

@Pushpesh'使用的表類型不支持FULLTEXT索引' – Michelle 2012-04-09 12:49:44

回答

0
SELECT * 
FROM posts 
WHERE 
    `title` LIKE '%android%' 
OR `content` LIKE '%android%' 
0
$sql = "SELECT * FROM posts WHERE `title` LIKE '%$SearchTerm%' OR `content` LIKE '%$SearchTerm%'"; 
1
SELECT 
    * 
FROM 
    posts 
WHERE 
    lower(`title`) LIKE '%android%' 
    OR lower(`content`) LIKE '%android%' 
+0

這是否意味着lettercase不被忽略? – Michelle 2012-04-09 10:32:38