luminous Posted January 12, 2009 Share Posted January 12, 2009 Hi Everyone! I'm new to the board, I found out about this sight earlier last week I've been coding PHP for about two months now but I thought i'd probably learn new things alot quicker by joining some kind of community! I've just got a small problem with this PHP tag cloud code i'm working on. The font size for the links of the cloud were coming out huge, i've traced it down the source of the problem which is the '$range' variable which is responsible for subtracting the highest value in the 'counts' field from my db from the lowest which is 57 - 1 . However when I echoed out this value the number is '563236'! i've tried to use the ceil() and floor() functions but to no avail. Can someone tell me what i'm doing wrong? Thanks in advance! $query = "SELECT item AS tag, count AS count FROM tags GROUP BY item ORDER BY item ASC"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $tags[$row['tag']] = $row['count']; } $maxSize = 250; $minSize = 100; $maxQty = max(array_values($tags)); $minQty = min(array_values($tags)); echo $maxQty."<br/>"; echo $minQty."<br/>"; $range = floor($maxQty - $minQty); echo "range: ".$range; if(0 == $range) { $range = 1; } foreach ($tags as $key => $value) { $size = ceil($minSize + (($value - $minQty) * $range)); echo '<li><a href="#" class="tag" style="font-size:'.$size.'%">'.$key.'</a>'; echo ' <span class="count">('.$value.')</span></li>'; echo '</ul>'; } Quote Link to comment https://forums.phpfreaks.com/topic/140567-simple-php-tag-cloud-problem/ Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 round()? That might not work, as it is all designed to work with decimals mainly. Maybe look through http://www.unitedscripters.com/index.html?file=/phps/manual3.html&ref=google%20php%20manual%20number%20functions Quote Link to comment https://forums.phpfreaks.com/topic/140567-simple-php-tag-cloud-problem/#findComment-735591 Share on other sites More sharing options...
luminous Posted January 12, 2009 Author Share Posted January 12, 2009 Yep that got it to round to 56! However the links are still a massive size so i'll have to look into this further. The strange thing is though when removed the round() from the code and refreshed the page it was still 56! maybe something to do with the cache? Quote Link to comment https://forums.phpfreaks.com/topic/140567-simple-php-tag-cloud-problem/#findComment-735601 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Or something to with the values in the db, have they changed? Quote Link to comment https://forums.phpfreaks.com/topic/140567-simple-php-tag-cloud-problem/#findComment-735602 Share on other sites More sharing options...
luminous Posted January 12, 2009 Author Share Posted January 12, 2009 Nope, haven't changed anything with the db values. It's got to be something small but I just can't find it! Quote Link to comment https://forums.phpfreaks.com/topic/140567-simple-php-tag-cloud-problem/#findComment-735621 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.