
Originally Posted by
gwpaul
It would appear that my AND statements are not working or correct.
it's actually caused by you mixing ANDs and ORs
they work like addition and multiplication
for example, what is 1+2*3 ? is it 1+(2*3) or (1+2)*3 ?
to mix ANDs and ORs, always use parentheses to ensure you get exactly the logic you want

also, another thing that is affecting your results is this --
Code:
attorney.firm_id = 'law_firm.firm_id'
the attorney's firm_id is never going to be equal to that character string
let's revise the query to avoid the ORs problem...
Code:
SELECT attorney.fname
, attorney.initial
, attorney.lname
, attorney.email
, attorney.att_image
, attorney.lawyer_description
, law_firm.firm_name
, law_firm.street
, law_firm.suite
, law_firm.city
, law_firm.state
, law_firm.zip
, law_firm.phone
, law_firm.fax
, law_firm.url
, law_firm.description
, law_firm.realestate
, law_firm.business
, law_firm.criminal
, law_firm.bankruptcy
, law_firm.family_law
, law_firm.labor
, law_firm.estate
, law_firm.pi
, law_firm.general
FROM law_firm
LEFT
JOIN attorney
ON attorney.firm_id = law_firm.firm_id
WHERE '$_POST[county]' IN ( law_firm.county_0
, law_firm.county_1
, law_firm.county_2
, law_firm.county_3
, law_firm.county_4 )
AND law_firm.state = '$state'
AND law_firm.status = '2'
finally, you have a repeating group in the law_firm table, those 5 county columns -- these should be normalized into a separate table because as they are now, they will slow down this query
Bookmarks