etrader Posted August 25, 2011 Share Posted August 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted August 25, 2011 Share Posted August 25, 2011 Show us the code you have thus far and we will help you improve it Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 25, 2011 Share Posted August 25, 2011 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>'; } Quote Link to comment Share on other sites More sharing options...
DavidAM Posted August 25, 2011 Share Posted August 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 25, 2011 Share Posted August 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
etrader Posted August 25, 2011 Author Share Posted August 25, 2011 Thanks folks! I got the point Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.