Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Problems SmartyPaginate

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
bokhalifa
Smarty n00b


Joined: 05 Oct 2004
Posts: 4

PostPosted: Tue Oct 05, 2004 8:14 am    Post subject: Problems SmartyPaginate Reply with quote

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
View user's profile Send private message Send e-mail
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Oct 05, 2004 2:21 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Oct 05, 2004 2:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
bokhalifa
Smarty n00b


Joined: 05 Oct 2004
Posts: 4

PostPosted: Tue Oct 05, 2004 5:40 pm    Post subject: Reply with quote

Thanks mohrt Cool
Back to top
View user's profile Send private message Send e-mail
Isidor128
Smarty Regular


Joined: 27 Jul 2004
Posts: 35
Location: France

PostPosted: Fri Oct 08, 2004 1:59 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Oct 08, 2004 2:06 pm    Post subject: Reply with quote

Oops, you are correct! The sql query has zero-index when using limit.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Oct 08, 2004 2:12 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP