how can i create a tagging system using php and mysql?

后端 未结 2 1461
孤城傲影
孤城傲影 2020-12-22 23:18

wondering how i can create a tagging system in php and with a mysql database, my initial thoughts were to create a row in the table where the articles are stored, named tags

2条回答
  •  醉梦人生
    2020-12-22 23:49

    You're describing a many-to-many relationship between Articles and Tags. You'd want to use an intermediate junction table to resolve that relationship.

    enter image description here

    Now, to find all articles that match a selected tag:

    SELECT a.article_title
        FROM Tag t
            INNER JOIN Article_Tag_Xref atx
                ON t.tag_id = atx.tag_id
            INNER JOIN Article a
                ON atx.article_id = a.article_id
        WHERE t.tag_name = 'SelectedTagName'
    

提交回复
热议问题