From 6e43094d1037639bb481e3b6940f8bc5095603ec Mon Sep 17 00:00:00 2001 From: Naomi Date: Fri, 2 Aug 2013 11:18:15 -0400 Subject: [PATCH] pagination working properly (but not with filtering, have removed serach for now anyways.) --- .../application/services/HistoryService.php | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/services/HistoryService.php b/airtime_mvc/application/services/HistoryService.php index 56e75eef9..9311be640 100644 --- a/airtime_mvc/application/services/HistoryService.php +++ b/airtime_mvc/application/services/HistoryService.php @@ -188,6 +188,22 @@ class Application_Service_HistoryService " LEFT JOIN {$filter} USING(history_id)"; } + //need to count the total rows to tell Datatables. + $stmt = $this->con->prepare($mainSqlQuery); + foreach ($paramMap as $param => $v) { + $stmt->bindValue($param, $v); + } + + if ($stmt->execute()) { + $totalRows = $stmt->rowCount(); + Logging::info("Total Rows {$totalRows}"); + } + else { + $msg = implode(',', $stmt->errorInfo()); + Logging::info($msg); + throw new Exception("Error: $msg"); + } + //------------------------------------------------------------------------ //Using Datatables parameters to sort the data. @@ -224,6 +240,16 @@ class Application_Service_HistoryService $mainSqlQuery.= " ORDER BY {$orders}"; } + + $displayLength = intval($opts["iDisplayLength"]); + //limit the results returned. + if ($displayLength !== -1) { + $mainSqlQuery.= + " OFFSET :offset LIMIT :limit"; + + $paramMap["offset"] = $opts["iDisplayStart"]; + $paramMap["limit"] = $displayLength; + } $stmt = $this->con->prepare($mainSqlQuery); foreach ($paramMap as $param => $v) { @@ -240,8 +266,6 @@ class Application_Service_HistoryService throw new Exception("Error: $msg"); } - $totalRows = count($rows); - //----------------------------------------------------------------------- //processing results.