dongnai5905 2019-04-26 13:35
浏览 87
已采纳

MySQLi:如何排序制作阶梯

I'm setting up a website based on server voting's. I would like to sort servers votes with mysqli and give them a rank, per example:

1: 88 votes Server1

2: 54 votes Server2

3:34 votes Server3...

I already have my servers and votes in my database, but I can't find the solution to sort them and to give them a rank. It is like:

{rank} : {number of server's vote} {server name}

I already tried this:

    $totalserv = $database->prepare("SELECT COUNT(*) FROM `servers` ");

    $votes = $database->query("SELECT `votes` FROM `servers` ORDER BY votes ASC");

But I don't understand how to make $vote a list and attribute it a rank.

  • 写回答

1条回答 默认 最新

  • dps43633 2019-04-26 13:41
    关注

    You can try this, change DESC and ASC accordingly

    SELECT *  FROM `table` ORDER BY LEFT(`votes`,2) DESC;
    

    Your query

    $votes = $database->query("SELECT `votes` FROM `servers` ORDER BY LEFT(`votes`,2) ASC");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记