Support the ongoing development of Laravel.io →
Database Eloquent

Hi,

I am trying to fetch ALL rows from a table in my dB. I need to get all rows because the data is displayed in a DataTable and then I am allowing people to filter through the rankings.

The script isn't even completing. I just get a white screen: http://clashdata.tk/clans/orderby/warswon/load

This is the Code:

public function warswonload(){
        $count = Clans::count();
        DB::statement(DB::raw("SET @rownum = 0"));
        $sql = "@rownum := @rownum+1 AS rank, id, clanid, name, location, level, exp, warslost, warstied, warwinpercent, warswon, playercount, score";
        $clan = Clans::orderBy('warswon', 'DESC')
            ->selectRaw($sql)
            ->get();

        return  [
            'draw' => 1,
            'recordsTotal' => $count,
            'recordsFiltered' => count($clan),
            'data' => $clan,
        ];
    }

What can I do to get this to have all the results returned within seconds?

I did this on MySql command line through SSH and it took 26.55 seconds for the query to complete.

There are ~157K rows altogether.

Thanks!

Last updated 3 years ago.
0

Any ideas?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

shivampaw shivampaw Joined 30 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.