Jump to content

pagination never works


froot
 Share

Recommended Posts

yes! I can confirm that @matjazp's solution works for me as well! As you might be able to see when comparing my actual code and the example / prove of concept code, I was getting close.

As for the load from db or load from in-memory, I've always been confused about this stuff. If you don't mind my asking: is that basic php knowledge or specific to PW? 
I actually need to load the pages and filter them twice because I have two subsections to be displayed on the page. So I don't know how to do that properly, without loading all at once. And I don't know how I would accomplish all of this in the given scenario, with the custom PaginatedArray and all, but I'm curious to find out and appreciate your input.

That said, I can also confirm that 

2 hours ago, matjazp said:

$items = $pages->find("template=basic-page, limit=$limit, body!=''");

works now. I'm almost certain though that I've used this syntax before with the empty single quotes so I'm very sceptical. Or I'm delirious. It's like the first approach one would use before ending up with what I did (building that function sortOutEmpty() etc. so I seriously doubt I didn't try that out before.

  • Like 1
Link to comment
Share on other sites

@fruid - I'll admit the database vs in-memory can be somewhat confusing in PW in terms of what selectors are support for one but not the other. This definitely needs improvement and better documentation, but I don't think that is really relevant in this case. Once you assign an array of pages to a variable and then do a find on that, you are using an in-memory selector - you're not querying the database anymore. This means if you are loading so many results that you need to paginate, then you're losing some of the benefits of pagination. This is not PW specific or even PHP specific.

Regarding the two subsections - are you grouping results into these subsections? It's hard for me to advise on that without having an example of exactly what you are trying to do.

 

  • Like 1
Link to comment
Share on other sites

forget the part where I said I need to filter it twice because the second part would not be paginated anyway, just have a limit, that's all.

The way you explain it, I think I didn't get it too wrong after all, just wasn't so lucky implementing it.
So how would I go about paginating it without storing everything in-memory but instead accessing the database directly (?) given the above starting point?

Link to comment
Share on other sites

11 hours ago, matjazp said:

$items = $pages->find("template=basic-page, limit=$limit, body!=''");

I need to correct myself, the above, as expected, doesn't work or at least very inconsistently.

So I'm now using the version with the sortOutEmpty function, which is a working solution. The downside I believe is that it's all loaded in memory now before paginating, so I'm still on the lookout for a better solution. Thanks so far.

Link to comment
Share on other sites

  • 1 month later...
On 5/29/2021 at 2:40 AM, fruid said:

I need to correct myself, the above, as expected, doesn't work or at least very inconsistently.

So I'm now using the version with the sortOutEmpty function, which is a working solution. The downside I believe is that it's all loaded in memory now before paginating, so I'm still on the lookout for a better solution. Thanks so far.

Does it make a difference if you move the negation?

$items = $pages->find("template=basic-page, limit=$limit, !body=''");

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...