Welcome Guest, Not a member yet? Register   Sign In
Just when I thought I had Pagination put to bed...
#1
Question 
(This post was last modified: 11-03-2020, 01:56 PM by Gary.)

I've experienced a hiccup with pagination... this time when it comes to the sort order of results.

If I do this:
Code:
$model->select('name, status, date, timezone, .....')->where('name', $name)->whereIn('status', STATUS_ARRAY)->orderBy('date', 'DESC');

and there happens to be a many records that have the an identical date (more than what will fit on a single pagination's page), I find that the orderBy constraint causes the results presented on the different pages to frequently have repetitions of records on several pages (and some of the records that should be displayed are missed- perhaps replaced by the repeated ones?).

Without making my lazy brain do any thinking, I find after a little experimenting, that if I do this:
Code:
$model->select('name, status, date, timezone, .....')->where('name', $name)->whereIn('status', STATUS_ARRAY)->orderBy('date DESC, id DESC');

the problem appears to go away.

* the 'date' field is a unix timestamp (int).

My concern is that I have many pages that use pagination (all with ordered sets of results) that will probably, at some point, have results that are ordered by a value that is repeated many times (more than what will fit on a single page)... which looks like it will then break the pagination's display (?).

So my questions are:

1) am I doing something stupid?
2) has anyone else noticed/experienced this problemĀ of paging with an orderBy?
3) is there a more sensible workaround than adding an additional, superfluous (but unique) id field to the orderBy that just creates more work for the query (and more importantly, probably causes a table-scan vs an indexed search/sort in the database)?

Thanks.
Reply


Messages In This Thread
Just when I thought I had Pagination put to bed... - by Gary - 11-03-2020, 11:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB