3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2278 Views |
-
Using MySQL SELECT SUM

26 March 2009 at 11:57am
Is there a SilverStripe function that has similar behavior to using the
statement?SELECT SUM(NumVisit) FROM 'Member';
Cheers
-
Re: Using MySQL SELECT SUM

27 March 2009 at 2:43am
Hi!
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)Docs:
http://api.silverstripe.org/sapphire/model/DataObjectSet.html#CountHope that helps,
Ben -
Re: Using MySQL SELECT SUM

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(); -
Re: Using MySQL SELECT SUM

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!
| 2278 Views | ||
|
Page:
1
|
Go to Top |



