Re: simple mysql query...
Gawie Marais wrote:
> SELECT count(sid) FROM system WHERE customercode = '$customercode' AND pkgid = '9' or pkgid = '10' or pkgid = '11' or pkgid = '12'
>
> its returning the count for all records where customercode = $customercode in stead of also
> taking into account that pkgid must also be = to 9,10,11,12
You have your precedence wrong.
You could write (note the parentheses):
SELECT count(sid) FROM system WHERE customercode = '$customercode' AND (pkgid = 9 or pkgid = 10 or pkgid = 11 or pkgid = 12)
But the standard way is:
SELECT count(sid) FROM system WHERE customercode = '$customercode' AND pkgid IN (9, 10, 11, 12)
Also note that, at least when pkgid has a numeric datatype (e.g. INTEGER), you don't want to write quotes around the literal values 9, 10, 11 and 12; the same holds for customercode.
--
felix
Please use
BBCode to format your messages in this forum.