Is there a SilverStripe function that has similar behavior to using the
SELECT SUM(NumVisit) FROM 'Member';
statement?
Cheers
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Is there a SilverStripe function that has similar behavior to using the
SELECT SUM(NumVisit) FROM 'Member';
statement?
Cheers
Hi!
If you can load the data into a DataObjectSet, you can use that class' Count() method.
$submissions = DataObject::get('BrowserPollSubmission');
$total = $submissions->Count();
Docs:
http://api.silverstripe.org/sapphire/model/DataObjectSet.html#Count
Hope that helps,
Ben
Not quite, Count will return the number of members, not the sum of their visits.
There is an SQL query object that can do this sort of thing:
$sqlQuery = new SQLQuery(
"SUM(NumVisit)", // Select
"Member", // From
"" // Where (optional)
);
$totalVisits = $sqlQuery->execute()->value();
Oops! I'm not sure why I thought subvert was referring to SQL Count instead of Sum. Thanks for catching that, Hamish!