imarockstar Posted August 11, 2008 Share Posted August 11, 2008 I am working on this tag cloud on my site. everything works great. Although I cant figure out how to display information as title tag in the link. here is the code I am using, and this work fine. function tag_info() { $result = m_q("SELECT * FROM pic_tags GROUP BY tag ORDER BY RAND() LIMIT 20"); while($row = mysql_fetch_array($result)) { $arr[$row['tag']] = $row['count']; } ksort($arr); return $arr; } function tag_cloud() { $min_size = 10; $max_size = 30; $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(); foreach ($tags as $tag => $count) { $size = $min_size + ($count - $minimum_count) * ($max_size - $min_size) / $spread; $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" href="tagedphoto.php?tag=' . $tag . '" returned a count of ' . $count . ' title="' . $description . '" ">' . htmlspecialchars(stripslashes($tag)) . ''; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; } As you can see, I added the $description to the title tag within the link, although its not pulling the data from the database. I believe I have not defined it within the function, but Im not sure ... any clue to whats going n here ? thx bobby Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/ Share on other sites More sharing options...
sasa Posted August 11, 2008 Share Posted August 11, 2008 try <?php function tag_info() { $result = m_q("SELECT * FROM pic_tags GROUP BY tag ORDER BY RAND() LIMIT 20"); while($row = mysql_fetch_array($result)) { // add both data to returned array $arr[$row['tag']] = array($row['count'], $row['description']); } ksort($arr); return $arr; } function tag_cloud() { $min_size = 10; $max_size = 30; $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(); foreach ($tags as $tag => $count) { $size = $min_size + ($count - $minimum_count) * ($max_size - $min_size) / $spread; //change output to $count[0](count) and $count[](description) //add ending a tag $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" href="tagedphoto.php?tag=' . $tag . '"> returned a count of ' . $count[0] . ' title="' . $count[1] . '" ">' . htmlspecialchars(stripslashes($tag)) . '</a>'; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; } ?> not tested Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-613599 Share on other sites More sharing options...
imarockstar Posted August 11, 2008 Author Share Posted August 11, 2008 I got this error ... Fatal error: Unsupported operand types in /home/franklin/public_html/sites/dwf/includes/func.php on line 37 you can view the site here: http://franklinspirko.com/sites/dwf/ Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-613683 Share on other sites More sharing options...
sasa Posted August 11, 2008 Share Posted August 11, 2008 which line is 37? Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-613697 Share on other sites More sharing options...
imarockstar Posted August 11, 2008 Author Share Posted August 11, 2008 line 37: $spread = $maximum_count - $minimum_count; Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-613758 Share on other sites More sharing options...
sasa Posted August 11, 2008 Share Posted August 11, 2008 change lines $tags = tag_info(); $minimum_count = min(array_values($tags)); $maximum_count = max(array_values($tags)); to $tags = tag_info(); foreach ($tags as $t) $tags1[] = $t[0]; $minimum_count = min($tags1); $maximum_count = max($tags1); Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-613791 Share on other sites More sharing options...
imarockstar Posted August 11, 2008 Author Share Posted August 11, 2008 nope .. Fatal error: Unsupported operand types in /home/franklin/public_html/sites/dwf/includes/func.php on line 48 line 48: $size = $min_size + ($count - $minimum_count) Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-613933 Share on other sites More sharing options...
sasa Posted August 11, 2008 Share Posted August 11, 2008 change $size = $min_size + ($count - $minimum_count) to $size = $min_size + ($count[0] - $minimum_count) Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-613950 Share on other sites More sharing options...
imarockstar Posted August 11, 2008 Author Share Posted August 11, 2008 ok this is what I have .... function tag_info() { $result = m_q("SELECT * FROM pic_tags GROUP BY tag ORDER BY RAND() LIMIT 20"); while($row = mysql_fetch_array($result)) { // add both data to returned array $arr[$row['tag']] = array($row['count'], $row['desc']); } ksort($arr); return $arr; } function tag_cloud() { $min_size = 10; $max_size = 30; $tags = tag_info(); foreach ($tags as $t) $tags1[] = $t[0]; $minimum_count = min($tags1); $maximum_count = max($tags1); $spread = $maximum_count - $minimum_count; if($spread == 0) { $spread = 1; } $cloud_html = ''; $cloud_tags = array(); foreach ($tags as $tag => $count) { $size = $min_size + ($count[0] - $minimum_count) * ($max_size - $min_size) / $spread; //change output to $count[0](count) and $count[](description) //add ending a tag $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' . '" class="tag_cloud" title=" '. $desc .' " href="tagedphoto.php?tag=' . $tag . ' ">' . htmlspecialchars(stripslashes($tag)) . '</a>'; } $cloud_html = join("\n", $cloud_tags) . "\n"; return $cloud_html; } but its not showing the description i have in the database for the variable $desk ( i currently only have 1 description inputed in the database, its for the tag AWARD WINNING ) this is the page where the tag cloud is : http://franklinspirko.com/sites/dwf/index.php Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-614035 Share on other sites More sharing options...
sasa Posted August 12, 2008 Share Posted August 12, 2008 change $desc to $count[1] Quote Link to comment https://forums.phpfreaks.com/topic/119154-tag-cloud-help/#findComment-614550 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.