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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀