3341 Posts in 982 Topics by 703 members
|Go to End|
26 March 2009 at 11:57am
Is there a SilverStripe function that has similar behavior to using thestatement?
SELECT SUM(NumVisit) FROM 'Member';
27 March 2009 at 2:43am
If you can load the data into a DataObjectSet, you can use that class' Count() method.
$submissions = DataObject::get('BrowserPollSubmission');
$total = $submissions->Count();
(Example from: http://doc.silverstripe.org/doku.php?id=tutorial:3-forms#showing_the_poll_results)
Hope that helps,
27 March 2009 at 8:42am Last edited: 27 March 2009 8:43am
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();
27 March 2009 at 9:07am
Oops! I'm not sure why I thought subvert was referring to SQL Count instead of Sum. Thanks for catching that, Hamish!
|Go to Top|