I hope someone can help with the following. I’m trying to create a user-specific search feature. When someone is logged in, they can run a search which should return results from either the customer_ref or order_details columns.
I have tried the following, but it returns results from different customers.
SELECT *
FROM `job`
WHERE c_name = 'John Doe'
AND customer_ref LIKE '%do%'
OR order_details LIKE '%do%'
I want to restrict the results to a specific customer (for obvious reasons). If I remove the bottom line (OR order_details LIKE '%do%'), the results are locked into the customer correctly, however, when it’s there I get results including other customer names.
Note that %do% is just a wildcard search term indicating door or Doreen (for testing). In the actual code it would be the value entered in the search box.
Many thanks in advance!
You need to include round brackets in your query to clarify on what terms you are searching: