Solved

mysql query issue

Posted on 2009-05-18
3
208 Views
Last Modified: 2012-05-07
Hi:
I have the query below however even so the product is inactive in the database (active = 0) it still shows with the query below even so I require products.active = 1. Any ideas about what I am doing wrong?
SELECT * FROM products 

LEFT JOIN usertable ON usertable.idusr = products.vendorID 

LEFT JOIN products_keywords ON products_keywords.IDproducts = products.id 

WHERE products.ProdName LIKE %s OR products.ProdShortDesc LIKE %s OR products.ProdLongDesc LIKE %s OR usertable.company LIKE %s OR products_keywords.keyword2 LIKE %s AND products.active = 1

Open in new window

0
Comment
Question by:michael789
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24412826
you are missing ()-;
SELECT * FROM products 
LEFT JOIN usertable ON usertable.idusr = products.vendorID 
LEFT JOIN products_keywords ON products_keywords.IDproducts = products.id 
WHERE ( products.ProdName LIKE %s OR products.ProdShortDesc LIKE %s OR products.ProdLongDesc LIKE %s OR usertable.company LIKE %s OR products_keywords.keyword2 LIKE %s)
  AND products.active = 1

Open in new window

0
 
LVL 3

Expert Comment

by:DABOMB
ID: 24419146
angelIII is correct, your 'AND products.active' is only being connected with the 'products_keywords.keyword2 LIKE %s' therefore those 2 conditions would have to be true to make the statement true OR any of the other statements. if you do what angellll says and put the () around all of the ORs then those will do the logical OR and then REQUIRE the active as well.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now