Reputation: 4337
i am getting this error when trying to perform the following query:
$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");
the problem seems to be the where partcount > 0
. it seems to be seeing the 0 as a boolean when trying to make the comparison?
Upvotes: 0
Views: 29484
Reputation: 31740
The value of $sql is probably false. This happens if the query you tried to execute failed to execute, usually due to a syntax error in the SQL.
Generally, you want your query code to look like this:
if ($result = mysql_query ('SELECT * FROM foo WHERE bar = \'baz\''))
{
// resultset processing goes here
while ($row = mysql_fetch_assoc ($result))
{
}
}
else
{
echo (mysql_error ());
}
Upvotes: 2