Display mySQL images by category and / or tag

I am relatively new to PHP / mySQL and I am trying to develop a portfolio of my images. I have already created an admin control panel where I can upload a photo from the hard drive and store image data (including its path) in the database. I am wondering if anyone can point me to a tutorial or information on how to set up a category and / or tag mechanism so that I can assign multiple tags / categories to an image and display them based on this.

For example, I have an image: npr_001_day.jpg. This is a "mountain" as well as a "winter" picture. I want to enable it, so when I click on the "mountains" link, it will be displayed. I also want it to appear when I click on the winter category.

I searched the Internet for a while and was able to find something useful.

Thanks for any help! Tre

+3
source share
1 answer

This is what is called a many-to-many relationship in a relational database. I assume you have an IMAGE table where the image data goes. You will need to add a CATEGORY table to store your categories and a CATEGORY_IMAGE table to store the relationship between images and categories.

CATEGORY_IMAGE will have two columns, one for the identifier of the image and one for the identifier of the associated category. Here is a pretty good overview of what you need - http://www.tomjewett.com/dbdesign/dbdesign.php?page=manymany.php

+2
source

Source: https://habr.com/ru/post/1793752/


All Articles