Jump to content

Tag column in mysql and tags cloud


etrader

Recommended Posts

I have a tag column in the table of posts. I store tags as "tag1,tag2,tag3,...". When displaying tags in the post, I explode to have an array. Everything is OK, but I cannot create a tags cloud; as I need to have the occurrence of each tag to increase the font. What is a practical trick to create tag clouds?

 

I think the common method is to build a table for post tags and store each single tag in a separate cell. But I hope to keep my database tidy.

Link to comment
Share on other sites

you could just do a random thing: (untested, off the top of my head)

 

$words = explode(",",$var); // assume this array holds your words
$sizes = array(10,13,16); // font sizes you want
foreach($words as $word){
   $size = rand(0,sizeof($sizes)); // randomly choose a size
   echo '<font size="'.$sizes[$size].'">'.$word.'</font>';
}

Link to comment
Share on other sites

I think the common method is to build a table for post tags and store each single tag in a separate cell. But I hope to keep my database tidy.

 

Using a separate table is the proper way to do it. It does not make the database un-tidy; it makes it normalized. You are not going to find an efficient or accurate way to query the tags if they are stored in a delimited field that way. Once they are in a separate table, it is very simple to determine the number of posts associated with each tag. As it is, you will have to read every post in the database to get a tag count, and you will have to read every post in the database to find all posts associated with a specific tag. This will put an unnecessary load on the database. Having a normalized database will actually result in less of a load when looking for tag counts, or posts associated with a tag, or any other query against the tags.

Link to comment
Share on other sites

I think the common method is to build a table for post tags and store each single tag in a separate cell. But I hope to keep my database tidy.

 

Using a separate table is the proper way to do it. It does not make the database un-tidy; it makes it normalized. You are not going to find an efficient or accurate way to query the tags if they are stored in a delimited field that way. Once they are in a separate table, it is very simple to determine the number of posts associated with each tag. As it is, you will have to read every post in the database to get a tag count, and you will have to read every post in the database to find all posts associated with a specific tag. This will put an unnecessary load on the database. Having a normalized database will actually result in less of a load when looking for tag counts, or posts associated with a tag, or any other query against the tags.

 

Yeah, what he ^^ said

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.