在多列中查找搜索词

时间:2012-04-09 10:25:41

标签: php mysql sql

如何在多列中搜索字词:titlecontent。例如:

$searchTerm = 'android';

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

3 个答案:

答案 0 :(得分:1)

SELECT 
  *
FROM 
  posts
WHERE
  lower(`title`) LIKE '%android%'
  OR lower(`content`) LIKE '%android%'

答案 1 :(得分:0)

SELECT *
FROM posts
WHERE
   `title` LIKE '%android%'
OR `content` LIKE '%android%'

答案 2 :(得分:0)

$sql = "SELECT * FROM posts WHERE `title` LIKE '%$SearchTerm%' OR `content` LIKE '%$SearchTerm%'";