SELECT WHERE IN使用文本字符串查询

时间:2013-04-05 12:20:23

标签: mysql select where concat

我已经看了一下,尝试了一些事情,但我似乎无法让这个工作......有人可以帮忙吗?

$typeall = " ('House','Condo','Loft','Townhouse','Land')";

$rs = mysql_query("SELECT * FROM 'houses' WHERE and category IN " .$typeall); 

不起作用

但如果我输入

$rs = mysql_query("SELECT * FROM 'houses' WHERE and category IN ('House','Condo','Loft','Townhouse','Land')"); 

它完美无缺,为什么?

感谢。

3 个答案:

答案 0 :(得分:0)

您应该删除and

WHERE and category IN ...

分为:

WHERE category IN ...

答案 1 :(得分:0)

试试这个:

$typeall = "'House','Condo','Loft','Townhouse','Land'";

$rs = mysql_query("SELECT * FROM 'houses' WHERE and category IN (".$typeall.")");

可能是变量$ typeall在括号中不起作用。

答案 2 :(得分:0)

不要引用表名,并删除额外的and

$typeall = " ('House','Condo','Loft','Townhouse','Land')";
$rs = mysql_query("SELECT * FROM houses WHERE category IN " .$typeall);