joshuag Posted June 29, 2012 Share Posted June 29, 2012 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, 1 Link to comment Share on other sites More sharing options...
apeisa Posted June 29, 2012 Share Posted June 29, 2012 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 More sharing options...
joshuag Posted June 29, 2012 Author Share Posted June 29, 2012 Awesome. Ok, I didn't know that. I thought PW got everything when I asked for it. This is great news. Thanks. Link to comment Share on other sites More sharing options...
ryan Posted June 29, 2012 Share Posted June 29, 2012 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. 1 Link to comment Share on other sites More sharing options...
joshuag Posted June 29, 2012 Author Share Posted June 29, 2012 ahh, great, thanks Ryan... strange that I didn't know about that one. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now