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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.