MySQL Query Problem
Posted: Thu Oct 09, 2003 9:58 am
I know this is a php forum, but since everyone here seem real smart and that many also are familar with mySQL, I have a question regarding a query that is giving me weird problems.
What is wrong with this query? When I take the "OR" argument out, the the query works, however, if I leave it in, the output is all messed up—data between table laos and table oikos don't matching up. It is like the argument "oikos.id = laos.oikos_id" is being ignored.
SELECT laos.lname, laos.fname, laos.directory, oikos.family, oikos.id, laos.oikos_id, oikos.address, oikos.city, oikos.st, oikos.zip, oikos.hphone, laos.wphone, laos.mphone, laos.email, laos.web, laos.pcell, DATE_FORMAT(laos.birthday, '%m-%d') AS birth, DATE_FORMAT(laos.aniversary, '%m-%d') AS wedding, UNIX_TIMESTAMP(DATE_ADD(laos.datestamp, INTERVAL 3 hour)) AS dstamp, laos.scell
FROM laos, oikos
WHERE oikos.id = laos.oikos_id AND laos.lname LIKE 'lastname%' AND laos.directory = 'Y' AND laos.pcell LIKE '$cell%' OR laos.scell LIKE '%$cell%'
ORDER BY laos.lname, laos.pfamily
What is wrong with this query? When I take the "OR" argument out, the the query works, however, if I leave it in, the output is all messed up—data between table laos and table oikos don't matching up. It is like the argument "oikos.id = laos.oikos_id" is being ignored.
SELECT laos.lname, laos.fname, laos.directory, oikos.family, oikos.id, laos.oikos_id, oikos.address, oikos.city, oikos.st, oikos.zip, oikos.hphone, laos.wphone, laos.mphone, laos.email, laos.web, laos.pcell, DATE_FORMAT(laos.birthday, '%m-%d') AS birth, DATE_FORMAT(laos.aniversary, '%m-%d') AS wedding, UNIX_TIMESTAMP(DATE_ADD(laos.datestamp, INTERVAL 3 hour)) AS dstamp, laos.scell
FROM laos, oikos
WHERE oikos.id = laos.oikos_id AND laos.lname LIKE 'lastname%' AND laos.directory = 'Y' AND laos.pcell LIKE '$cell%' OR laos.scell LIKE '%$cell%'
ORDER BY laos.lname, laos.pfamily