-1

I got problem when search data from database like this:
I had 1 record in database like this:
product.name = LED Backlight Square 6", 15W, E27, Golden Light - TL02-C615W
This is my query:
Keywords: LED Backlight Square
SQL:

SELECT * FROM product WHERE product.name LIKE "%led%" AND product.name LIKE "%blacklight%" AND product.name LIKE "%square%"    

The result is empty.
Where is my problem?

Python
  • 699
  • 5
  • 5
  • 2
    Does it work in your DB interface? If so please add your PHP usage. – user3783243 Dec 07 '18 at 04:17
  • Query looks okay, try to test it in new session. – M A Dec 07 '18 at 04:19
  • 1
    If you are using a table with a case sensitive collation then `LIKE` will also be case sensitive. – Nick Dec 07 '18 at 04:21
  • There's no php here and the api used to connect/query with is unknown given that you are using php to execute this. So your question cannot be answered in its present state. The collation as noted by @Nick could be at play here. If it works in phpmyadmin, then something else is causing your code to fail. If you want help, you'll need to respond to comments. However, if the answer below solved this, then there's a duplicate for this, possibly two. – Funk Forty Niner Dec 07 '18 at 04:28
  • Sorry, I just updated exact SQL I used in my code: `SELECT * FROM product WHERE product.name LIKE "%led%" AND product.name LIKE "%blacklight%" AND product.name LIKE "%square%"` – Python Dec 07 '18 at 05:03

1 Answers1

-1

Try to Do like this

SELECT * FROM product WHERE product.name LIKE '%led%' OR product.name LIKE '%blacklight%' OR product.name LIKE '%square%'  
Yogesh
  • 9
  • 3
  • 2
    Answers should have explanations. Please don't just post code on questions asking users to run it. It doesn't explain what the issue was to the user, nor future users. – user3783243 Dec 07 '18 at 04:19