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)
// i forced it to have 5 page of 25 items + 1 page with 1 item = 6 pages total (considering we set the page limit to 5 up there and the limit to 25)
$_data = range(1,126);
SmartyPaginate::setTotal(count($_data));
return array_slice($_data, SmartyPaginate::getCurrentIndex(),
SmartyPaginate::getLimit());
}
?>

I am working on a project where I receive data concerning availability information for a hotel in json format from an external site (I do not have control over the sql queries) and after I decode them I assign the whole data to a template variable. As I understand the $pagination variable is populated with SmartyPaginate::assign($smarty) but in my case the $smarty object contains many more data than only those who needs to be paginated. In particular the array to be paginated is an attribute of one of the objects that constitute the whole data returned.

The only way to populate the $paginate variable with only the portion of data I need is with the SmartyPaginate::assign($smarty, 'data_to_paginate', 'pageID') or there is another way?

I'm pretty new to PHP and Smarty, but i've made Smarty work in my own written website, now i was working on a nice error handler today and everything works fine, untill... i've visit a page where i use SmartyPaginate. I've got lots and lots of errors, mayB you can help me out with it? Because i realy like this plugin and i want to use it, but with so much errors i can;t work with it.

When I have a form and do a query which return results in 2 pages, I found problem on how to carry the query result in to the 2nd page and also back to 1st page as well.
Also when I use paginate in 2 separete php file, a.php and b.php, why when I move next in a.php?step=20 will cause link (a href) in b.php to read a.php?step=20?

As it appears, {$paginate.current_item} will ONLY output the correct value in the "default" instance and theres no support for {$paginate.current_item id="mydata"}, right ?

I know it's a bit late but I thought I'd post my solution for others as it'll probably come up again. After some tinkering and looking at the code, it dawned on me that the {paginate_first id='mydata'} is a smarty function, not a variable as with {$paginate.first}.

For this to work, your $paginate->assign() call must be correct.

Rather than just:

Code:

$paginate->assign($smarty)

You'll need to do something like:

Code:

$paginate->assign($smarty, 'paginate', 'mydata');

Essentially, you have to pass the correct var name (paginate) to smarty, along with the correct id (mydata).

Hope this helps.

- Dy

p.s. You'll note I reference assign as part of the $paginate method, rather than statically (SmartyPaginate::assign) due to PHP5 compatibility issues (as noted elsewhere here).

I have two questions:
1.) is there a way to support search engine friendly urls? e.g.: mypage/search/10, where 10 means the next field.

2.) Is it true, that the pagination engine creates a full array of all pages internally? At least I see this in the smarty debugging console. Whenever I have a bigger total size (>1000 items, limit 10), pagination slows down, because of creating the whole array.