如何通过无限滚动获得正确的排名?

时间:2017-03-01 07:10:29

标签: php mysql laravel-5 infinite-scroll

我根据网票获得视频排名。我得到了正确的结果

id     | net_votes| rank
------ | -------: |:----:
2      |    11    |   1
4      |    6     |   2
1      |    5     |   3
5      |    5     |   4
3      |    3     |   5

由于有很多视频并且避免加载问题,我尝试使用无限滚动。 当我使用无限滚动时,前5个视频显示正确的排名,当我向下滚动加载另外5个视频并将排名显示为1-5(错误排名)。排名正在检查这5个视频。 滚动时我需要连续排名。有谁可以帮我这个?

这是我的代码

    $subquery = "(
             SELECT    username,
                       net_votes,
                       contest_portfolio.id,
                       video,
                       portfolio_id,
                       Sum(net_votes) AS total,
             FROM      contest_portfolio
             LEFT JOIN portfolio
             ON        contest_portfolio.portfolio_id = portfolio.id
             LEFT JOIN users
             ON        portfolio.user_id = users.id
             LEFT JOIN profile
             ON        users.id = profile.user_id
             WHERE     contest_portfolio.status
             GROUP BY  contest_portfolio.id
             ORDER BY  total DESC,
                       contest_portfolio.created_at DESC ) totals,
                       (SELECT @r:=0) rank";

        $posts = DB::table(DB::raw($subquery))
            ->select(
                '*',
                'total',
                DB::raw('@r:=@r+1 as rank'),
                DB::raw('@l:=total'))
            ->paginate('5');

if ($request->ajax()) {
    $view = view('site.data',compact('posts'))->render();
    return response()->json(['html'=>$view]);
}

return view('my-post',compact('posts'));

0 个答案:

没有答案