Heath Posted July 22, 2007 Share Posted July 22, 2007 I have recently redesigned a clip dump script and I am trying to add the ability for people to submit tags for their items. Here is what I have done so far. I have added this to my websites functions file. function tag_info() { $result = mysql_query("SELECT * FROM tags GROUP BY tagName ORDER BY Rand() DESC"); while($row = mysql_fetch_array($result)) { $arr[$row['tagName']] = $row['count']; } //ksort($arr); return $arr; } function tag_cloud() { $min_size = 20; $max_size = 60; $tags = tag_info(); $minimum_count = min(array_values($tags)); $maximum_count = max(array_values($tags)); $spread = $maximum_count - $minimum_count; if($spread == 0) { $spread = 1; } $cloud_html = ''; $cloud_tags = array(); $step = ($max_size - $min_size)/($spread); foreach ($tags as $tag => $count) { $size = $min_size + ($count - $minimum_count) * $step; // $size = ($max_size + $min_size)/$spread; $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" href="http://localhost/content/tagcloud.php?s=' . $tag . '" title="\'' . $tag . '\' returned a count of ' . $count . '">' . htmlspecialchars(stripslashes($tag)) . '</a>'; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; } I then added this to my sites CSS .tag_cloud {padding: 3px; text-decoration: none; font-family: verdana; } .tag_cloud:link { color: #FF66CC; } .tag_cloud:visited { color: #9900FF; } .tag_cloud:hover { color: #FF66CC; background: #000000; } .tag_cloud:active { color: #6699FF; background: #000000; } div.wrapper{ position:absolute; height:200px; width:400px; } After that I added this code to my sites template <div id="wrapper" class="wrapper"> <?php print tag_cloud(); ?> </div> Last, I ran this MySQL code in phpmyadmin CREATE TABLE tags (TagID INT AUTO_INCREMENT NOT NULL PRIMARY KEY, tagName VARCHAR(50) NOT NULL, UNIQUE(tagName), TagActive INT NOT NULL DEFAULT 1); Currently I think the table is empty so there is nothing showing, but I am not getting any errors, so I am assuming its working properly. What I am now trying to do is add the ability for some one to add their own tags like so php, freaks, web design, doesnt matter and have them added to the database as single search terms any time the , comes up it knows that starts a new tag? Can some one help me with this please? I can't find any articles any where including the submission part. 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.