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
MySQL Query Problem
Moderator: General Moderators
We have an SQL section also... 
If I'm thinking correct about your issue, it might be because of:
Spot the difference? Adding () around something, makes that evaluate as on its own...
Move the () around to fit your needs. Additionally, you might read up on MySQL's JOIN's (not really an issue in this case, but worth reading).
Hope it helped.
If I'm thinking correct about your issue, it might be because of:
Code: Select all
select * from table where id = 1 and foo = bar or bar = foo
select * from table where id = 1 and (foo = bar or bar = foo)Code: Select all
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.pfamilyHope it helped.
- itsmani1
- Forum Regular
- Posts: 791
- Joined: Mon Sep 29, 2003 2:26 am
- Location: Islamabad Pakistan
- Contact:
Code: Select all
select id FROM їtable name] where id='$id' & abc='$abc'Abdul Mannan
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
Cruzado_Mainfrm
- Forum Contributor
- Posts: 346
- Joined: Sun Jun 15, 2003 11:22 pm
- Location: Miami, FL