duanliao3826 2011-11-09 11:08
浏览 16

为mysql中的用户获取每个游戏的前3个结果

My problem is I need to return the list of each 'game_id' where the 'user_id' is in the top three of 'score' and his position. My mysql table is as follows:

pk_hiscore_id
game_id
user_id
score

How would I do this?

  • 写回答

1条回答 默认 最新

  • dqwh1209 2011-11-10 23:03
    关注

    Use this query and mysql_fetch_assoc the result:

    SELECT * FROM `table_name` ORDER BY `score` DESC LIMIT 0,3
    

    Then, loop through the resulting array like this:

    // Assume that $array is the array you loaded the query result into.
    
    for ($position = 1; $position <= 3; $position ++)
    {
        $game_id = $array[$i-1]["game_id"];
    
        echo "Game ID: " . $game_id . "
    ";
        echo "User Position: " . $position;
    }
    

    Unless I am understanding you incorrectly, that should give you the information you want.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?