I am building a website that will have a searchable product database. For the sake of simplicity, my table has three columns:
- id
- img (a reference to an image of the product)
- tags (varchar 255, a list of tags used for searching, ex. "chair wood brown")
I have the query:
$query = "SELECT `img` FROM `products` WHERE `tags` LIKE '%$q%'";
This works exactly how I want it to, with the only problem being that it would only select rows if the tags were in the order searched. For example, if there were 3 rows:
- Row 1 with tags "black tray"
- Row 2 with tags "tray black"
- Row 3 with tags "black tray layer"
And you searched for "black tray", both Row 1 and Row 3 would display, but not Row 2.
I'm trying to get all three rows to be displayed, no matter the order of words. I want, for example, if you searched "black tray", for them all to be displayed, but if you searched "tray layer", then only Row 3 would be displayed. Perhaps this will require re-thinking the original query, I'm not sure.
Many thanks!