Jump to content

how to count items without getting the results.


joshuag
 Share

Recommended Posts

Hi,

I am wondering, is there a way to count items in the DB without returning the results? I have a site that is going to have 10,00 pages and I want to count them all.

Using $pages->find(selector)->count; returns the results and I guess this is the same as count($pages->find()) just counting how many items are in the returned wire array. Not what I want. I want to count items without the overhead of getting all the data.

Thanks,

  • Like 1
Link to comment
Share on other sites

Actually I think there is very little overhead of doing that, since PW doesn't load the data until it is used (or if you have autojoin set on your fields). And if you don't have to loop all those pages it will be breeze.

You can also do this:

$pages->find(selector, limit=2)->getTotal()

But I guess it does pretty much the same under the hood (not sure though) - removes the limit and counts it.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...