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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.