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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:50:05+00:00 2026-05-31T11:50:05+00:00

I’m working on a tags feature and this is my database structure so far:

  • 0

I’m working on a tags feature and this is my database structure so far:

`tags` Table:      `content` Table:

id | tagname       id | title       | tags
------------       -----------------------
 1 | fire           1 | Charizard   | 1 3
 2 | water          2 | Blastoise   | 2
 3 | flying         3 | Charmander  | 1

What is the best method for using these two tables and outputting the proper tags for each item of content?
If I was to call for my tags in this manner:

$query = mysql_query("SELECT * FROM `content`");

while ($tableData = mysql_fetch_array($query)) {
    echo $tableData["tags"];
}

It would obviously output the raw text content 1 3 and 2 and 1 respectively.
I want it to display fire flying and water and fire respectively.

What should I do to grab those tagnames using the information given from the tags column in the content table?

  • 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-31T11:50:07+00:00Added an answer on May 31, 2026 at 11:50 am

    Yes, you should study normalization and change your table to 3NF. First of all this will save you some huge headaches down the line, and second, normalization is really cool. Here’s a very fast summary of what you’d be doing:

    Having all your tags in one field is bad practice. It means that everything that will ever query your database has to know exactly how you’re storing them and how to pull them apart. It also means that you won’t be able to use pure SQL to ask questions like “how many pokemon have a fire attribute” or “which tag is the most popular” because SQL doesn’t know what your space-delimited list of tags means. Instead, you’d split content into two tables: monsters and attributes. Monsters looks like this:

    id | name
    ---|---------
     1 |Charizard
     2 |Blastoise
    ...
    

    And attributes looks like this:

    monsterid | tagid
    ----------|----------
            1 | 1
            1 | 3
            2 | 2
    ...
    

    To get a monster’s attributes, you find its name in the monsters table, get its ID, and use its ID to find its attributes from the attributes table. This is trivial using JOIN and it gives you a great deal of power to retrieve your information in interesting ways.

    To answer your original question, you’d do something like this:

    SELECT monsters.id as monsterid, monsters.name, tags.tagname from monsters 
        INNER JOIN attributes ON (monsters.id = attributes.monsterid)
        INNER JOIN tags ON (tags.id = attributes.tagid)
        ORDER BY monsters.id
    

    And you’d get a results table that looks like this:

    monsterid | name      | tagname
    ----------|-----------|--------
            1 | charizard | fire
            1 | charizard | flying
            2 | blastoise | water
    ....
    

    Then you could iterate over the rows that were returned and do something like:

    $monsters = array();
    while ($tableData = mysql_fetch_array($query)) {
        $monstername = $tabledata['name'];
        if(!isset($monsters[$monstername])) { $monsters[$monstername] = array(); }
        $monsters[$monstername][] = $tabledata['tagname'];
    }
    

    And then finally you’ll have what you wanted, an array where each element is identified by a monster’s name, and the value is an array with all that monster’s tags.


    … Seriously, I know this sounds hellishly complicated compared to what you were originally asking, but I believe it’s the simplest way to do it that’s not likely to blow up in your face. Hopefully someone will correct me if I’m badly wrong.

    warning – the code here was written off the top of my head. There may be some errors in it, but it should show you how to implement the solution.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Does anyone know how can I replace this 2 symbol below from the string

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.