Find actual row count without LIMITs applied

Addresses #542
This commit is contained in:
Sebastian Grewe 2013-07-31 17:09:30 +02:00
parent 15728375bb
commit 4c37ab4950
2 changed files with 10 additions and 4 deletions

View File

@ -8,6 +8,7 @@ class Transaction {
private $sError = '';
private $table = 'transactions';
private $tableBlocks = 'blocks';
public $num_rows = 0;
public function __construct($debug, $mysqli, $config, $block, $user) {
$this->debug = $debug;
@ -89,6 +90,7 @@ class Transaction {
$this->debug->append("STA " . __METHOD__, 4);
$sql = "
SELECT
SQL_CALC_FOUND_ROWS
t.id AS id,
a.username as username,
t.type AS type,
@ -142,8 +144,13 @@ class Transaction {
LIMIT ?,?
";
$stmt = $this->mysqli->prepare($sql);
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $start, $limit) && $stmt->execute() && $result = $stmt->get_result())
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $start, $limit) && $stmt->execute() && $result = $stmt->get_result()) {
// Fetch matching row count
$num_rows = $this->mysqli->prepare("SELECT FOUND_ROWS() AS num_rows");
if ($num_rows->execute() && $row_count = $num_rows->get_result()->fetch_object()->num_rows)
$this->num_rows = $row_count;
return $result->fetch_all(MYSQLI_ASSOC);
}
$this->debug->append('Unable to fetch transactions');
return false;
}

View File

@ -10,11 +10,10 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) {
}
if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$iLimit = 30;
$iLimit = 4;
$debug->append('No cached version available, fetching from backend', 3);
$aTransactions = $transaction->getAllTransactions(@$_REQUEST['start'], @$_REQUEST['filter'], $iLimit);
$iCountTransactions = $transaction->getCountAllTransactions();
$aTransactionTypes = $transaction->getTypes();
$iCountTransactions = $transaction->num_rows;
if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg');
$smarty->assign('LIMIT', $iLimit);
$smarty->assign('TRANSACTIONS', $aTransactions);