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;
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 C# TCP服务端,客户端退出后,不断有数据进来
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?