mardi 28 février 2017

how to get correct rank with infinite scroll?

Im getting video's rank according to net votes. im getting the correct results like this

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

Due to lots of videos and avoid loading issue, I tried to use infinite scroll. when I use infinite scroll first 5 videos shows correct rank, when I scroll down loading another 5 videos and rank shows as 1-5 (wrong rank). rank is checking for those 5 videos. I need to get continuous rank when I scroll. anyone can help me on this?

here is my code

    $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'));



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire