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

  • Home
  • SEARCH
  • 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 9188215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:57:08+00:00 2026-06-17T19:57:08+00:00

I have a database setup like this: post_id | title 1 | Some Title

  • 0

I have a database setup like this:

post_id | title

1 | Some Title

2 | Another Title


tag_id | tag

1 | tag01

2 | tag02


post_id | tagt_id

1 | 1

1 | 2

2 | 1

I have joined these tables with the following code:

$this->db->select('*');
$this->db->from('posts');
$this->db->join('posts_tags', 'posts.post_id = post_tags.post_id', 'inner');
$this->db->join('tags', 'posts_tags.tag_id = tags.tag_id', 'inner');

In my view, I can access the tag by using

$post['tag']

This results in a duplicate post for every tag associated with it.

The question is how do i loop through all tags associated with one post?

The expected output would be:

post_id 1 = tag01, tag02

instead of

post_id 1 = tag01

post_id 1 = tag02

  • 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-17T19:57:09+00:00Added an answer on June 17, 2026 at 7:57 pm

    If you intent is simply to look for tags related only to a single post, you would need to filter your query to only look for the post you are concerned with using a WHERE clause.

    If your intent is to return all tags for all posts, but have each post only have one row with the tags listed as comma-separated values (or similar), you would need to look at using a GROUP_CONCAT function in your SELECT like this:

    SELECT pt.post_id AS `post_id`, GROUP_CONCAT(t.tag) AS `tags`
    FROM post_tags AS pt
    INNER JOIN tags AS t ON pt.tag_id = t.tag_id
    GROUP BY `post_id`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a database like this: This is set up to give role-wise
I have a website. That is setup like this: /public_html index.php common.php db.php /dev
I have an SQL database set up in which I would like to use
I have a SQLite database setup for my android application and I have it
If you've got a database setup in Django, how can you have the TestRunner
I have setup a database view. When users import the data from the view
I have setup multiple SQL Service Broker Queues in a database but have not
We have replication setup on a database and is working fine. Now we want
I have a tool that is setup to query our Clearquest Database to return
currently I'm trying to have a setup where a generic database is distributed to

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.