Solved

mysql query issue

Posted on 2009-05-18
3
209 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

911 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

16 Experts available now in Live!

Get 1:1 Help Now