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 7719245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:22:01+00:00 2026-06-01T03:22:01+00:00

I hope someone here can help me.. I am currently having a small issue

  • 0

I hope someone here can help me..

I am currently having a small issue when dealing with tags in PHP and MySQL. So far, I am able to added tags when a new post is created. The only problem that I am facing if actually repopulating the checkbox list with tags from the particular post.

This is my table structure

Posts:

id |
title |
content |
date_created |
date_modified

Tags:

id |
tag_name

Post_Tags:

post_id |
tag_id

I have a single interface for managing the posts and tags at the same time. I could have used 2 interfaces but that wouldn’t be efficient. I can add the post and the relevant tags easily to the corresponding tables quite easily when the form is submitted. I just want to be able to have the relevant checkboxes selected when a particular post is about to be edited.

using this SQL code to retrieve the post and all its tags but all it has returned is just one tag yet there are 4 tags associated with this post:

   SELECT *
   FROM (`posts`)
   LEFT JOIN `post_tags` ON `post_tags`.`post_id` = `posts`.`id`
   LEFT JOIN `tags` ON `post_tags`.`tag_id` = `blog_tags`.`id`
   WHERE  `id`  LIKE '%104%'
   GROUP BY `blog_posts`.`id_art`

With that not working, i decided to create 2 queries. One that will list all the available tags and the other that will list the tags belonging to a post and basically do a nested foreach loop. I have has some kind of success, the only problem here is that the checkbox is being repeated 4 times. I.E. lets same, the post has tags such as books, movies, videos and games, the result is as follows:

books
books
books
books
movies
movies
movies
movies
etc….

That keeps on going for all the 10 tags that are listed.

<div style="overflow-y:auto; width: 350px; height: 200px;">
     <?php foreach ($blog_tags as $tag) : ?>
     <?php foreach($post_tags as $t) : ?>
          <?php echo form_checkbox('tags[]',$tag->id_tag,(!empty($blog_article) && $t->tag_id == $tag->id_tag) ? TRUE : FALSE); ?> <?php echo $tag->name_tag; ?><br />
      <?php endforeach; ?>
      <?php endforeach; ?>
</div>

Can anyone point out why the code is behaving the way it is? Thanks

Sam

PS. Sorry if this is so long….

  • 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-06-01T03:22:03+00:00Added an answer on June 1, 2026 at 3:22 am

    Sounds like a SQL problem to me. I think your second approach will be easiest to use. You can just SELECT * FROM tags to get all of your tag information. Then SELECT * FROM posts LEFT JOIN post_tags ON posts_id = post_tags.post_id. which would get all of the tag IDs associated with this post. You can then match those IDs up to the list of tags you already retrieved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope someone can help here, we're having an incredibly annoying time with Visual
Ok guys, I hope someone here can help me. I got a bunch of
I have looked all over for an answer and hope someone here can help.
I hope that someone can help me with this problem that I've been having
I hope someone here can help me! :) Actually I've run into a wall
thats my first question here and i hope someone can help me. I´m new
I am pretty new to javascript so I hope someone here can help me
I hope someone here can help me, i been trying to create an placeable
I hope someone here can help me. Im using selenium to test a page
I really hope someone here can help out with this. I'm using Magento 1.6.1.0

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.