duanmie9741 2016-05-22 19:40
浏览 36
已采纳

获取数据库中的玩家下一个等级 - Laravel 5.2

I'am using the Halo 5 API, and I'm trying to get a players total Progress till their next rank. In order to do that, one of the steps is I have to get a players next rank. From there on I can get the start Xp of that rank.

I know how to get a players current rank with its Start XP. What I cant figure out is how to get the next rank ( or row ) from the database.

This is how my function is set up right now:

 public function currentProgressRank($playerArenaStats) {

        // Get a players current xp and rank from API JSON array
        $PlayersRankXP = $playerArenaStats->Results[0]->Result->Xp;
        $PlayersRank = $playerArenaStats->Results[0]->Result->SpartanRank;

        // Get a Players current Rank from Database by comparing a players rank from API to a rank ID from Database
        $GetStartXp = Ranks::where('rank_id', '=', $PlayersRank)->get();


        // Do a foreach loop, and get the start XP into the current rank
        foreach ($GetStartXp as $XP) {
            $GetStart = $XP->startXp;
        }


        // Need to get Start Xp for the Players next rank here....

    }

I know there is the next() method, but how would I implement that into a laravel eloquent search

  • 写回答

1条回答 默认 最新

  • dounan4479 2016-05-22 20:41
    关注

    I figured out, like this:

            // Get the start Xp of next rank for Player
            $GetStartXpOfNextRank = Ranks::where('rank_id', '=', $PlayersRank + 1)->get();
    
            foreach ($GetStartXpOfNextRank as $XPNext) {
                $GetStartXPNext = $XPNext->startXp;
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划