Jump to content

mysql query for posts tags


alepou77

Recommended Posts

Hello everyone,

I have "Posts" table in my model. "Posts" table have these columns : ID , title , image , category , description , body , author , created_date. I want to extend my "Posts" table by adding a column "tags". I want my php website to compare one post with others by "tags".  Is it this option good? or I must make a different table with foreign keys and tags. Please anwser me if you can the mySQL queries and the right database Model. Thenks

Link to comment
https://forums.phpfreaks.com/topic/284959-mysql-query-for-posts-tags/
Share on other sites

Your best bet is to have three tables: 'posts', 'tags' and 'post_tags'. The structure of the Posts table remains the same. Tags is comprised of tagID and tagName columns. Post_tags links the tags in the Tags table to the appropriate Post using foreign keys on ID and tagID. This means that a post can now have multiple tags connected with it, retrieving other posts with the same tags is a lot quicker and it can also be done in a single SQL statement.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.