dorpbn1027 2013-06-10 18:19
浏览 13
已采纳

标记前3个条目

my question is finding out how to label the top 3 entries based on column "avg_score, in a table, while still showing the rest of the entries, but without a label. So say I have a table like this:

 Entry   avg_score

entry_1 | 4.3
entry_2 | 9.4
entry_3 | 4.6
entry_4 | 7.1
entry_5 | 2.1
entry_6 | 1.9

I want to be able to find the top 3 based on the column 'avg_score' and display it like:

"1st place: entry_2

2nd place: entry_4

3rd place: entry_3

entry_1

entry_5

entry_6"

Any help would be appreciated!

  • 写回答

2条回答 默认 最新

  • duanshan3331 2013-06-10 18:25
    关注

    At first you must make your query which would order by avg_score desceing.

    After that you can do something like this:

    <?
    $x = 1;
    while($row = mysql_fetch_array($q)){
        if($x < 4){
            echo $x.". place: ";
        }
        echo $row['Entry'];
    }
    ?>
    

    if you want it to show 1st etc then use:

    <?
    $x = 1;
    while($row = mysql_fetch_array($q)){
        if($x == 1){echo "1st place: ";
        }elseif($x == 2){echo "2nd place: ";
        }elseif($x == 3){echo "3rd place: ";}
        echo $row['Entry']."<br />";
        $x++;
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥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时遇到的编译问题