From 30e0e49ee73423742dfe49dcf0cec3611dc5bf0b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sat, 31 Oct 2020 14:09:47 -0400 Subject: [PATCH] Fix total rows when using search --- web/ajax/events.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/ajax/events.php b/web/ajax/events.php index 200416f92..c8008e8a2 100644 --- a/web/ajax/events.php +++ b/web/ajax/events.php @@ -181,6 +181,9 @@ 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'; $query['sql'] = 'SELECT ' .$col_str. ' FROM `' .$table. '` AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id'.$where.' ORDER BY ' .$sort. ' ' .$order. ' LIMIT ?, ?'; @@ -195,6 +198,10 @@ function queryRequest($filter, $search, $advsearch, $sort, $offset, $order, $lim } $rows = array(); + $results = dbFetchAll($query['sql'], NULL, $query['values']); + if ( ! $results ) { + return $data; + } foreach ( dbFetchAll($query['sql'], NULL, $query['values']) as $row ) { $event = new ZM\Event($row); if ( !$filter->test_post_sql_conditions($event) ) { @@ -222,8 +229,6 @@ function queryRequest($filter, $search, $advsearch, $sort, $offset, $order, $lim } $data['rows'] = $rows; - # 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 ' .$table. ' AS E'. ($filter->sql() ? ' WHERE '.$filter->sql():''), 'Total'); #$data['total'] = count($rows); return $data; }