更改热门标签的字体大小

I have a few static tags in a table.

And I'm trying to track clicks on the static tags, and i have seen on other sites (and it actually really good) that the popular tags changes is size.

Have a look at this image: enter image description hereThis image presents the expected output.

The table looks like this:

+-----------+--------+
|    tag    | clicks |
+-----------+--------+
| Falun     | 45     |
| Stockholm | 229    |
| Borlänge  | 77     |
| ...       | ...    |
| ...       | ...    |
+-----------+--------+

More clicks, the "bigger" font size. But font size should be max 40px, and min 5px.

How can I from MySQL and PHP calculate difference in clicks and present it in font-size?

SELECT tag, (SELECT COUNT(percentage) FROM tags) AS tag_size FROM tags

Then

foreach($tags as $tag){
    <a href="#" style="font-size: <?php echo $tag->tag_size ?>px"><?php echo $tag->tag ?></a>
}

Very sorry for pseudo code, but i have no idea how to do this!

So you can use group by to pull all the tag records together. Then you can use ifs to set your font size. Something like:

$sql = 'SELECT tag, count(clicks) AS tag_size FROM tags group by tag';
$sth = $dbh->prepare($sql);
$sth->execute();
$result = $sth->fetchAll();
foreach($result as $row) {
    $size = $row['tag_size'];
    if($size >700 ){
        $font_size = 40;
    } elseif($size >650 ){
        $font_size = 39;
    } elseif($size >650 ){
        $font_size = 38;
    }...
    else {
        $font_size = 5;
}

First you need to find the maximum number of clicks:

SELECT MAX(`clicks`) FROM `tags`;

Let's assume this is assigned to a variable called $max_clicks. You then need to scale the point sizes according to this value. The formula you use to do this is entirely up to you, but scaling according to the square root of the click count should produce reasonable results:

if ($max_clicks > 0) { // Avoid divide-by-zero error if nothing has been clicked
  $sqrt_max_clicks = sqrt($max_clicks);
  $query = "SELECT `tag`, 5 + 35 * SQRT(`clicks`) / $sqrt_max_clicks FROM `tags`;"
  // ... (Generate tag markup) ...
}

Obviously, 5 is the minimum point size, and 35 is the difference between the maximum and minimum point sizes. I'm assuming here that you want tags to appear in the tag list even if they have a click count of zero.