For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > April 2005 > Using SmartyPaginate Plugin









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using SmartyPaginate Plugin
Reynier Perez Mira

2005-04-11, 4:02 pm

Well list, I found SmartyPaginate Plugin on Smarty Plugins Repository and I need to use him beacuse I have a Guestbook in my site and the results must be show start in 1 and end in 5. I see the example that came with him but I not understand some things. Take a look to example:

File: index.php

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

session_start();
require('Smarty.class.php');
require('SmartyPaginate.class.php');
$smarty =& new Smarty;
// required connect
SmartyPaginate::connect();
// set items per page
SmartyPaginate::setLimit(25);
// assign your db results to the template
$smarty->assign('results', get_db_results());
// assign {$paginate} var
SmartyPaginate::assign($smarty);
// display results
$smarty->display('index.tpl');

function get_db_results() {
// normally you would have an SQL query here,
// for this example we fabricate a 100 item array
// (emulating a table with 100 records)
// and slice out our pagination range
// (emulating a LIMIT X,Y MySQL clause)
$_data = range(1,100);
SmartyPaginate::setTotal(count($_data));

return array_slice($_data, SmartyPaginate::getCurrentIndex(),Smarty
Paginate::getLimit());
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

In first: Why Smarty is instance $smarty object by reference and not normally? I see this in considerably examples. The second is: If a try to paginate results from a query, where is the query? I not see them into the example code? Where they should stay?

Regards



Reynier Pérez Mira

3ero. Ing. Informática

Entre más inteligente me siento, más me doy cuenta de lo ignorante que soy.




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com