我在尝试执行以下查询时遇到此错误:
$sql = mysql_query("select c.id as id_car, c.year, c.make, c.model, c.type, c.colour,
(select count(*) from `parts` where `id_car`=c.id and `is_packaged`='yes') as partcount
from `cars` as c
where partcount > 0
group by c.id
order by `id` desc");
问题似乎是where partcount > 0
。在尝试进行比较时似乎将0视为布尔值?
答案 0 :(得分:2)
$ sql的值可能是假的。如果您尝试执行的查询无法执行,通常会由于SQL中的语法错误而发生这种情况。
通常,您希望查询代码如下所示:
if ($result = mysql_query ('SELECT * FROM foo WHERE bar = \'baz\''))
{
// resultset processing goes here
while ($row = mysql_fetch_assoc ($result))
{
}
}
else
{
echo (mysql_error ());
}