Jump to content

simple php tag cloud problem


luminous

Recommended Posts

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>';
}

Link to comment
https://forums.phpfreaks.com/topic/140567-simple-php-tag-cloud-problem/
Share on other sites

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.