From 7650e0bf5174180409fcc997e77e08cef40cde59 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 2 Nov 2020 12:43:45 -0500 Subject: [PATCH] cleanup my totalNotFiltered code. Join Monitors as well as they can be referenced by the filter --- web/ajax/events.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/web/ajax/events.php b/web/ajax/events.php index 769bd29d9..e6ec9ec0b 100644 --- a/web/ajax/events.php +++ b/web/ajax/events.php @@ -181,8 +181,6 @@ function queryRequest($filter, $search, $advsearch, $sort, $offset, $order, $lim if ( $where ) $where = ' WHERE '.$where; - # total has to be the # of available rows. Not sure what totalNotFiltered is actually used for yet. - $data['totalNotFiltered'] = $data['total'] = dbFetchOne('SELECT count(*) AS Total FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id'. $where, 'Total', $query['values']); $sort = $sort == 'Monitor' ? 'M.Name' : 'E.'.$sort; $col_str = 'E.*, M.Name AS Monitor'; @@ -229,15 +227,14 @@ function queryRequest($filter, $search, $advsearch, $sort, $offset, $order, $lim } $data['rows'] = $rows; - if ( 0 ) { # totalNotFiltered must equal total, except when either search bar has been used - $data['totalNotFiltered'] = dbFetchOne('SELECT count(*) AS Total FROM ' .$table. ' AS E'. ($filter->sql() ? ' WHERE '.$filter->sql():''), 'Total'); + $data['totalNotFiltered'] = dbFetchOne( + 'SELECT count(*) AS Total FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id'. ($filter->sql() ? ' WHERE '.$filter->sql():''), 'Total'); if ( $search != '' || count($advsearch) ) { - $data['total'] = dbFetchOne('SELECT count(*) AS Total FROM ' .$table. ' AS E'.$where , 'Total', $wherevalues); + $data['total'] = dbFetchOne('SELECT count(*) AS Total FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id'.$where , 'Total', $wherevalues); } else { $data['total'] = $data['totalNotFiltered']; } - } return $data; } ?>