douyou1937 2015-12-12 23:51
浏览 83

更改热门标签的字体大小

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 here This 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!

  • 写回答

2条回答 默认 最新

  • doujianqin5172 2015-12-13 00:46
    关注

    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;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题