FILTERS

I am building a mini project, on a wine warehouse and as I do not have much knowledge in back-end I am in doubt of how I can do product search filters, for example the wine has the year, type of wine, region and how can I cosntrui a search bar that makes this filter by the database data.
2 Replies
Jochem
Jochem11mo ago
generally you'd write a WHERE statement for your SQL query based on the search term, something like
SELECT * FROM wines WHERE `name` LIKE @searchterm OR `year` LIKE @searchterm OR `type` LIKE @searchterm
SELECT * FROM wines WHERE `name` LIKE @searchterm OR `year` LIKE @searchterm OR `type` LIKE @searchterm
how you do wildcards in prepared statements varies a bit by the SQL flavor though
Kikky#1902
Kikky#190211mo ago
It depends what kind of database your are using and the structure of your database. In the example above type should probably store ID reference to type model/table or enum. Region also if you want maintainable and scalable database system.