I have created a search bar for my website, the user may search a specific category, man or woman etc by a selecting this option from a drop down menu, then entering in a keyword which searches against the selection. The product names all have multiple words, e.g Ultracool Aero Vest or Cyclone Jacket etc…
This is my query, the variable $term is the passed keyword:
$query = "SELECT * FROM PRODUCTS WHERE CATALOGUEID = (SELECT CATALOGUEID FROM PRODUCT_CATALOGUE WHERE PRODUCT_NAME LIKE '%" . $term . "%') AND category1 = 1 ";
Now this works, but I need to enter the entire product name for it to find anything, I am racking my brains trying to figure out how to allow a user to search by entering only one word such as, jacket or vest. I have been researching this and experimenting with regular expressions and wildcards, but I have not been successful, I am not sure if this is even possible. The W3 schools site does show examples of how to search parts of some words, but not multiple words.Any advice is appreciated.
I am editing my question, as I have to inform everyone that I am using SQL server 2008 and cannot use any MySQL syntax. I keep forgetting that I need to distinguish this when posting questions regarding SQL. Apologies.
I managed to figure out how to do this eventually, all along my problem was using = instead of IN, here is the query now working perfectly, note I am no longer concatenating the keyword wildcard:
Thanks for all your input and help on this.