0

I am confused about how to go about doing the following task using PHP and SQL:

I have an image database with the following columns: title, keywords, desc, date_entered, image_link.

The keywords column has values stored like this: value1;value2;value; ...

Now I have to provide a form to users in which they can enter one or more keywords and they will get all the images in the result that have these keywords attached to them in the database.

Users are also required to enter the keywords in this formate: value1;value2; ... but they are not required to enter all the related keywords to get any specific image in the result, even a single keyword should return some images in the result if the keyword matches any images.

I can not just do " ... where $enteredKeywords like keywords"; because the user may have not entered all the keywords for an image and it may never exactly match to an image record in the database. I am not sure how can I accomplish this task.

Riken
  • 1
  • 3
  • 1
    Please share more details. Why not use a normalized database format, where keywords are stored in a seperate table? – Nico Haase Jul 06 '21 at 06:20
  • If you read [How to split a comma-separated value to columns](https://stackoverflow.com/questions/10581772/how-to-split-a-comma-separated-value-to-columns), then you know how to get a list of values, and not a comma (or semi-colon) splitted list of values. After that, the solution is standard SQL. – Luuk Jul 06 '21 at 06:22
  • Does this answer your question? [Sql select the elements match to array and display them in a row](https://stackoverflow.com/a/35416890/5882307) – OMi Shah Jul 06 '21 at 06:22

0 Answers0