|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Ee Smarty Rookie
Joined: 20 Dec 2004 Posts: 9
|
Posted: Sun Jan 23, 2005 6:07 am Post subject: Some undefined error from SmartyPaginate |
|
|
SmartyPaginate-1.2
ADODB Library for PHP4
// Pagination
require('./includes/smarty/SmartyPaginate.class.php');
// required connect
SmartyPaginate::connect();
// set items per page
SmartyPaginate::setLimit(10);
$sql = "SELECT users.*,jawatan.jawatan FROM users,jawatan WHERE users.id_jawatan = jawatan.id AND users.id != '" . $_SESSION['id'] . "' LIMIT ". SmartyPaginate::getCurrentIndex() . ", ". SmartyPaginate::getLimit();;
$rs = $this->db->Execute($sql);
SmartyPaginate::setTotal($rs->RecordCount());
echo SmartyPaginate::setUrl('./index.php?mod=users&act=view');
$this->tpl->assign('results', array_slice($rs->fields, SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit()));
SmartyPaginate::assign($this->tpl);
Ok, the problem is i just got 10 results (should be 128). But if i set setTotal to the real number of rows, i got some undefined errors, but the pagination is working
Notice: Undefined index: format in E:\Workspace\Website\sim\includes\smarty\plugins\function.paginate_middle.php on line 59
Notice: Undefined variable: _ret in E:\Workspace\Website\sim\includes\smarty\plugins\function.paginate_middle.php on line 72 |
|
Back to top |
|
barma3 Smarty Rookie
Joined: 12 May 2005 Posts: 5
|
Posted: Sun May 29, 2005 1:31 pm Post subject: |
|
|
In your case $rs->RecordCount() returns number of records in your SQL query, where you are using limit param. So you have got 10 strings. Use separate query for SmartyPaginate::setTotal().
This is my variant:
Code: |
function get_db_results($table) {
global $db;
$_query = "SELECT SQL_CALC_FOUND_ROWS * FROM $table";
$_result = $db->PageExecute($_query, SmartyPaginate::getLimit(), SmartyPaginate::getCurrentIndex());
if (!$_result) print ($db->ErrorMsg());
while (!$_result->EOF) {
$_data[] = $_result->GetRowAssoc(false);
$_result->MoveNext();
}
// now we get the total number of records from the table
$_query = "SELECT FOUND_ROWS()";
$_result = $db->Execute($_query);
if (!$_result) print ($db->ErrorMsg());
$_row = $_result->GetRowAssoc();
SmartyPaginate::setTotal($_row['FOUND_ROWS()']);
return $_data;
}
|
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|