$reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED);
- $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_daily} ORDER BY timeend');
- $earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_weekly} ORDER BY timeend');
- $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_monthly} ORDER BY timeend');
+ $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}');
+ $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}');
+ $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
global $CFG, $DB;
if ($mode == STATS_MODE_DETAILED) {
- $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_user_daily} ORDER BY timeend');
- $earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_user_weekly} ORDER BY timeend');
- $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_user_monthly} ORDER BY timeend');
+ $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_daily}');
+ $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_weekly}');
+ $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_monthly}');
} else {
- $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_daily} ORDER BY timeend');
- $earliestweek = $DB->get_field_sql('SELECT timeend FROM {stats_weekly} ORDER BY timeend');
- $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_monthly} ORDER BY timeend');
+ $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}');
+ $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}');
+ $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}');
}
$navigation->add(get_string('stats'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', ''));
}
}
-}
\ No newline at end of file
+}
global $CFG, $DB;
// are there any data in stats table? Should not be...
- if ($timeend = $DB->get_field_sql('SELECT timeend FROM {stats_'.$str.'} ORDER BY timeend DESC')) {
+ if ($timeend = $DB->get_field_sql('SELECT MAX(timeend) FROM {stats_'.$str.'}')) {
return $timeend;
}
// decide what to do based on our config setting (either all or none or a timestamp)
switch ($CFG->statsfirstrun) {
case 'all':
- if ($firstlog = $DB->get_field_sql('SELECT time FROM {log} ORDER BY time ASC')) {
+ if ($firstlog = $DB->get_field_sql('SELECT MIN(time) FROM {log}')) {
return $firstlog;
}
default: