Jump to content

Recommended Posts

Posted

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
Posted

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.

Posted

Awesome. Ok, I didn't know that. I thought PW got everything when I asked for it. This is great news. Thanks.

Posted

We also have an API function for this:

$total = $pages->count("selector"); 

It basically works the same as @apeisa's example and is fast/low overhead.

  • Like 1

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
  • Recently Browsing   0 members

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