Lambneck Posted August 17, 2009 Share Posted August 17, 2009 Hello I am having trouble with this tag cloud script. Currently it displays the tag cloud but doesnt change the size of highly used tags. Im guessing it has something to do with the count row of my database being empty. If so, how to allow the row "count" to recognize a repeatative tag? this is what my table looks like id post_id tag count Here is the code: function get_tag_data() { require 'cloud_data.php'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); $result = mysql_query("SELECT * FROM $table GROUP BY tag ORDER BY count DESC"); while($row = mysql_fetch_array($result)) { $arr[$row['tag']] = $row['count']; } ksort($arr); return $arr; } function get_tag_cloud() { // Default font sizes $min_font_size = 12; $max_font_size = 30; // Pull in tag data $tags = get_tag_data(); $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(); // create an array to hold tag code foreach ($tags as $tag => $count) { $size = $min_font_size + ($count - $minimum_count) * ($max_font_size - $min_font_size) / $spread; $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" href="tags.php?id=' . $tag . '" title="\'' . $tag . '\' returned a count of ' . $count . '">' . htmlspecialchars(stripslashes($tag)) . '</a>'; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; } print get_tag_cloud(); Link to comment https://forums.phpfreaks.com/topic/170616-solved-tag-cloud/ Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 Not to sure if this'll work, its a shot in the dark. [php <?php function get_tag_data() { require 'cloud_data.php'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); $result = mysql_query("SELECT tag, count(id) AS tag_count FROM $table GROUP BY tag ORDER BY tag"); while($row = mysql_fetch_array($result)) { $arr[$row['tag']] = $row['tag_count']; } return $arr; } ?> [/code] Also removed your redundant sorting. Link to comment https://forums.phpfreaks.com/topic/170616-solved-tag-cloud/#findComment-899902 Share on other sites More sharing options...
Lambneck Posted August 17, 2009 Author Share Posted August 17, 2009 Sweet. That did it! Thanks DarkendSoul! Link to comment https://forums.phpfreaks.com/topic/170616-solved-tag-cloud/#findComment-899910 Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 Not to sure if this'll work, its a shot in the dark. <?php function get_tag_data() { require 'cloud_data.php'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); $result = mysql_query("SELECT tag, count(id) AS tag_count FROM $table GROUP BY tag ORDER BY tag"); while($row = mysql_fetch_array($result)) { $arr[$row['tag']] = $row['tag_count']; } return $arr; } ?> Also removed your redundant sorting. Link to comment https://forums.phpfreaks.com/topic/170616-solved-tag-cloud/#findComment-899914 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.