Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 962111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:27:11+00:00 2026-05-16T01:27:11+00:00

its when i starting trying implementing this that i got quite stuck. some business

  • 0

its when i starting trying implementing this that i got quite stuck.

some business rules

1 Post can have many Tags.
1 Tag can have many Posts

the database will look like.

  • Posts (id, title, body, …)
  • Posts_Tags (post, tag)
  • Tags (id, tag, …)

when i insert – straightforward

  • tags will come from user input as comma separated values
  • explode($tags) to get individual tags
  • foreach $tag
    • check if tag exists
    • if yes, get id
    • if no, insert tag & get id
  • insert post with tags

i am wondering if this is the best way? can i do away with the loop to chk if the tags exists? or simplify it into 1 query?

update a post, abit harder

  • how can i check if the user has updated any tags. another loop? but this time there will be some changes (italic)

  • explode($tags) to get individual tags

  • foreach $tag
    • check if this post has been tagged with this tag
    • if no,
      • does tag exists?
        • yes, get id
        • no, insert and get id
    • if yes, get id
  • update post with tags

hmm, … update is more confusing, how will u implement this?

i am using PHP 5.3, Zend Framework 1.10, Doctrine 2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:27:12+00:00Added an answer on May 16, 2026 at 1:27 am

    I think the post-tags relationship should be many-to-many; ie: posts have and belong to many tags. This can be implemented with a junction table. Here’s some literature on the subject. Then…

    Insert: Do the same thing you are doing now, except you can fetch all tags in one query :

    SELECT name FROM tags WHERE name IN ($tags)
    

    Update: The easy way out: Remove all current tags, insert tags as if they were all new. Or…

    $tags = explode(',' $_POST['tags']); // remove whitespaces
    
    # delete all current tags that were not included in the edit
    DELETE FROM post_tags WHERE post_id=$post_id AND tag_id NOT IN ($tags)
    
    # find out what the current tags are, use a JOIN to find out their labels
    SELECT tag_id FROM post_tags WHERE post_id=$post_id
    fetch results, remove found tags from $tags, then
    foreach new $tag, insert as if they were new
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to trap an http request, change some of its post parameters
I've been trying to figure this out but its starting to make me want
Hi I am trying to run WSAD in Client login but its not starting
I have the following data. I want to take veh variable, starting with its
I starting off a project and starting build some of its structure. I am
I have a table I am trying to generate reports from. Its basically a
I currently am starting a Java process, and am trying to get its PID
I realize that similar questions have been asked, but have spent hours trying to
I am new to Rails and am just implementing some basic applications. Just starting
I have an ASP.NET website and am having trouble capturing some specific requests that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.