Hi Guys,
I'm developing a script for a friend and have run into a problem. I'm trying to make a system whereby the user enters ingredients (like keywords or tags) and the system will output recipes based on the input. In the database I was planning to make it look something like:
ID (Primary) | Recipe | Ingredients
1 cake flour, sugar
and when the user enters ingredients such as flour, the script will return will cake. Using VARCHAR wouldn't work because querying
SELECT Recipe FROM $table WHERE Ingredients = flour
wouldn't return any results because there is no row where Ingredients are equal to just flour. and what about if the user inputted 'sugar, flour' the database wouldn't recognize them because 'sugar, flour' != 'flour, sugar'. So any easy way of doing this would be if the data were arrays of data in one field.
One thing I was thinking was to have about 20 columns and each ingredient in a separate column then for a php script to scan down every column until it finds a matching ingredient. Then it would log that ingredient and if all the ingredients are matched it returns a positive match on a recipe. However this idea is really long winded and would take hours to code. It would also be quite hard for a user to interact with it so does anyone have any better ideas?
Many Thanks