1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| function get_db_results() {
global $connStr,$user,$pass;
$dbh = new PDO($connStr, $user, $pass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare("SELECT * FROM db_guestbook ORDER BY creation ".$_data);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
$gdata = $stmt->fetchAll();
$stmt->closeCursor();
$stmt = null;
$_data = range(1,126);
SmartyPaginate::setTotal(count($gdata));
return array_slice($gdata, SmartyPaginate::getCurrentIndex(),SmartyPaginate::getLimit());
}
/**
* function load All message in guestbook
*
*/
function loadMessage(){
// required connect
SmartyPaginate::connect();
SmartyPaginate::setPageLimit(5);
// set items per page
SmartyPaginate::setLimit(10);
// assign your db results to the template
$this->smarty->register_block('dynamic', 'smarty_ClashBlock_Dynamic', false);
if (!$this->smarty->is_cached('guestbook/index.tpl',$this->get_db_results())) {
//$this->smarty->assign('gbook',$this->dbguestbook->loadData());
$this->smarty->assign('results', $this->gdata);
SmartyPaginate::assign($this->smarty);
}
} |
Partager