2012-04-09 84 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