|
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 |
bokhalifa Smarty n00b
Joined: 05 Oct 2004 Posts: 4
|
Posted: Tue Oct 05, 2004 8:14 am Post subject: Problems SmartyPaginate |
|
|
here my code
Code: |
<?php
session_start();
require('Smarty.class.php');
require('SmartyPaginate.class.php');
require('Class/conf_global.php');
$smarty =& new Smarty;
SmartyPaginate::connect();
SmartyPaginate::setLimit(25);
$result = $BO->query("SELECT * FROM news ORDER BY id DESC "))
while($news = $BO->fetch_array($result))
{
$ne[] = $news;
$smarty->assign('ne', $ne);
$smarty->assign('results', get_db_results());
}
$smarty->display('index.tpl');
function get_db_results() {
$_data = range(1,100);
SmartyPaginate::setTotal(count($_data));
return array_slice($_data, SmartyPaginate::getCurrentItem()-1, SmartyPaginate::getLimit());
}
?>
|
Code: |
<tr>
<td class='bitTitle' colspan="2">{$tit}</td>
</tr>
<tr>
<td class="post1" width="95%" valign="top"> {$content}<br />{$Poster}</td>
</tr>
<br />
{* display results *}
{section name=res loop=$results}
{$results[res]}
{/section}
{* display pagination info *}
{paginate_prev} {paginate_middle} {paginate_next}
|
the code net workign
I hope your help me |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Oct 05, 2004 2:21 pm Post subject: |
|
|
For starters, setTotal() needs to contain the total number of rows from your database query, not the made up one from the paginate docs example. You are also needlessly reassigning template var "ne" within your fetch loop. You should collect all your rows into $ne first, then assign it once after the while loop. Something like:
[php:1:e0c1252eaa]$result = $BO->query("SELECT * FROM news ORDER BY id DESC "))
while($news = $BO->fetch_array($result))
{
$ne[] = $news;
}
SmartyPaginate::setTotal(count($ne));
$smarty->assign('ne', $ne);
[/php:1:e0c1252eaa] |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Oct 05, 2004 2:53 pm Post subject: |
|
|
You also need to apply the pagination data to your sql query:
Code: | SELECT * FROM news ORDER BY id DESC LIMIT X,Y |
Where "X" would be SmartyPaginate::getCurrentItem() and "Y" would be SmartyPaginate::getLimit(). |
|
Back to top |
|
bokhalifa Smarty n00b
Joined: 05 Oct 2004 Posts: 4
|
Posted: Tue Oct 05, 2004 5:40 pm Post subject: |
|
|
Thanks mohrt |
|
Back to top |
|
Isidor128 Smarty Regular
Joined: 27 Jul 2004 Posts: 35 Location: France
|
Posted: Fri Oct 08, 2004 1:59 pm Post subject: |
|
|
Hello
mohrt wrote: | You also need to apply the pagination data to your sql query:
Code: | SELECT * FROM news ORDER BY id DESC LIMIT X,Y |
Where "X" would be SmartyPaginate::getCurrentItem() and "Y" would be SmartyPaginate::getLimit(). |
I would say
"X" would be SmartyPaginate::getCurrentItem() -1
PS: I'm using 1.1 |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Oct 08, 2004 2:06 pm Post subject: |
|
|
Oops, you are correct! The sql query has zero-index when using limit. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Oct 08, 2004 2:12 pm Post subject: |
|
|
I have added the method getCurrentIndex() to the distribution which is basically the same thing as getCurrentItem() - 1. This will show up in the next release. |
|
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
|