Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

smarty_function_pager examples?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
renster
Smarty n00b


Joined: 12 Jun 2003
Posts: 1

PostPosted: Thu Jun 12, 2003 1:17 pm    Post subject: smarty_function_pager examples? Reply with quote

I was wondering if anyone had anymore complete examples of how to use smarty_function_pager. There is a online example included with the plugin but being the newb that I am, I can't get it to work. Even tried a simpler array than my example below but still no love.

Here is the example.

Code:
<{pager rowcount=$LISTDATA.rowcount limit=$LISTDATA.limit txt_first=$L_MORE class_num="fl" class_numon="fl" class_text="fl"}>


I am getting data out of a mySQL table containing country_id and country_name, into an associate array as per most standard examples and was outputting it to a simple table using {section} in the template. Straightforward (code shown for completeness). But with 230+ rows I wanted some pagination.

Code:
$db = DB::connect($dsn);
$sql = "SELECT country_id,country_name FROM country_table";

$countries = $db->getAll($sql, DB_FETCHMODE_ASSOC);

$smarty->assign('countries', $countries);

$smarty->display('body.tpl');

$db->disconnect();


and tpl

Code:
<html>
<head></head>
<body>
<table>
{section name="i" loop=$countries}
  <tr bgcolor="{cycle values="#ffffff,#bbbbbb"}">
      <td>{$countries[i].country_id}</td>
      <td>{$countries[i].country_name}</td>
   </tr>
{/section}
</table>
</body>
</html>


now how do I use pager? I tried adapting the example a few different ways with various complaints about no $limit set.

Any help appreciated. I was previously using pager and table classes from pear and had that working successfully but wanted a smarty way of doing it. Should I just be dealing with this with php code rather than through smarty plugins?
Back to top
View user's profile Send private message
Budda
Smarty Regular


Joined: 19 Apr 2003
Posts: 53
Location: Lymm, Cheshire. UK

PostPosted: Wed Jun 18, 2003 2:16 pm    Post subject: Reply with quote

If this is the same plugin as I'm using (by Pete Dudas?) then I can help you. I helped debug his plugin and got some new helpful stuff added.

Here's the Smarty code I use - placed in its own file then included at the bottom of any templates i use to display database records Very Happy
Code:

{math equation="$totalRecords / $perPage" assign="totalPages"}
{pager rowcount=$totalPages limit=1 shift=1 pos="pos" no_first=true separator="|" class_num="pager_num" class_numon="pager_numon" class_text="pager_text" txt_pos="side"}

$totalRecords = total number of results your paging through
$perPage = how many per page

now just set up some style sheet code to change the look of the displayed numbers. Magic! Its a great little plugin.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
idxman01
Smarty Rookie


Joined: 10 Jun 2003
Posts: 14
Location: FL

PostPosted: Wed Jun 18, 2003 7:04 pm    Post subject: Reply with quote

I get odd URL's with this plugin.

eg:

Code:

{pager rowcount=$total_pages limit=1 posvar="offset" no_first=false separator="|" txt_pos="side"}


produces:
Code:

http://domain/foo/index.php&offset=0


Shouldn't it be index.php?offset=0 ?

Also the offsets are off. If viewing page 1 for the first time offset is 0, but I set it to 1 for retrieval purposes.


Code:

   $offset = isset($vars['offset'])
      ? $vars['offset']
      : $_SESSION['offset'];

   if (!$offset) {
      $offset = 1;
   }

   $_REQUEST['offset'] = $offset;
   $_GET['offset']     = $offset;

   $sess->register('offset');


^the session remembers what page I'm on, so I don't have to fuss with the url's.

Any ideas?

-r
Back to top
View user's profile Send private message
Budda
Smarty Regular


Joined: 19 Apr 2003
Posts: 53
Location: Lymm, Cheshire. UK

PostPosted: Thu Jun 19, 2003 8:14 am    Post subject: Reply with quote

idxman01 wrote:
I get odd URL's with this plugin.

eg:

Code:

{pager rowcount=$total_pages limit=1 posvar="offset" no_first=false separator="|" txt_pos="side"}


produces:
Code:

http://domain/foo/index.php&offset=0


Shouldn't it be index.php?offset=0 ?

Have you downloaded the recent plugin update (recent as in March 2003) ? I had the same problem but the author fixed it. If the code isn't updated online I can send you a working version of the same plugin.
Quote:

Also the offsets are off. If viewing page 1 for the first time offset is 0, but I set it to 1 for retrieval purposes.
-r

In my example you will see I used an attribute
Code:
shift=1

stick that magic piece in and all offsets are shifted by 1. Wink
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
idxman01
Smarty Rookie


Joined: 10 Jun 2003
Posts: 14
Location: FL

PostPosted: Thu Jun 19, 2003 12:39 pm    Post subject: Reply with quote

I just download it from http://smarty.php.net/contribs/plugins/ the other day and it lists 2 changes in March'03.

-r
Back to top
View user's profile Send private message
Budda
Smarty Regular


Joined: 19 Apr 2003
Posts: 53
Location: Lymm, Cheshire. UK

PostPosted: Thu Jun 19, 2003 12:57 pm    Post subject: Reply with quote

idxman01 wrote:
I just download it from http://smarty.php.net/contribs/plugins/ the other day and it lists 2 changes in March'03.

-r

Does this mean that it still don't work? I can email you the 10k pager file if you wish?
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
duda
Smarty n00b


Joined: 02 Jul 2003
Posts: 2
Location: Budapest

PostPosted: Wed Jul 02, 2003 5:36 pm    Post subject: Reply with quote

The present version from the author can be found at http://www.netrendorseg.hu/smarty_contrib/function.pager.phps
Hopefully Budda sends me his improvments so I can merge it into the official release:)
Back to top
View user's profile Send private message
idxman01
Smarty Rookie


Joined: 10 Jun 2003
Posts: 14
Location: FL

PostPosted: Thu Jul 03, 2003 5:20 am    Post subject: Reply with quote

Quote:
* Last Modified: July 7, 2003


Sweet.. Futureware. Very Happy



I'll have to try it at work sometime soon.. Last time I tried budda's version (w/ the 4.14 changes), but it was doing something weird with the page numbers.. Can't recall exactly what it was at this point.

-r
Back to top
View user's profile Send private message
risto
Smarty Rookie


Joined: 26 Apr 2003
Posts: 21
Location: Norway

PostPosted: Fri Aug 29, 2003 7:37 pm    Post subject: still not making sence Reply with quote

what needs to be done to have the pager affect the array? it prints it all out anywhat!
Back to top
View user's profile Send private message
Budda
Smarty Regular


Joined: 19 Apr 2003
Posts: 53
Location: Lymm, Cheshire. UK

PostPosted: Mon Sep 01, 2003 8:47 am    Post subject: Re: still not making sence Reply with quote

risto wrote:
what needs to be done to have the pager affect the array? it prints it all out anywhat!
What do you mean by "affect the array" ? Confused
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
risto
Smarty Rookie


Joined: 26 Apr 2003
Posts: 21
Location: Norway

PostPosted: Wed Sep 03, 2003 6:28 am    Post subject: so effect Reply with quote

wel I get the pager up, but im still displaying the hole array, its not limiting the output! how doo I doo this?
Back to top
View user's profile Send private message
risto
Smarty Rookie


Joined: 26 Apr 2003
Posts: 21
Location: Norway

PostPosted: Wed Sep 03, 2003 8:37 am    Post subject: lol Reply with quote

forget it! forget it!
Back to top
View user's profile Send private message
pt2002
Smarty Regular


Joined: 05 May 2003
Posts: 89
Location: Porto, Portugal

PostPosted: Tue Sep 23, 2003 10:05 am    Post subject: Reply with quote

Hello

Quote:
The present version from the author can be found at http://www.netrendorseg.hu/smarty_contrib/function.pager.phps


It seems this link doesn't exist anymore.

Could someone provide a link to the enanced code or send it to me by email ?

TIA
Back to top
View user's profile Send private message
aholtzmann
Smarty n00b


Joined: 20 Mar 2004
Posts: 1
Location: Houston, TX

PostPosted: Sat Mar 20, 2004 6:39 am    Post subject: Updated pager Plugin Reply with quote

I think I've managed to track down the code for the final version of the pager plugin. I've updated the Wiki entry so you should be able to grab a copy of it there.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Adar
Smarty Regular


Joined: 27 May 2004
Posts: 58

PostPosted: Fri Jun 11, 2004 8:29 am    Post subject: Reply with quote

hi

i am still trying to get it to work... i did

Code:

{pager rowcount=$result[0].num limit=1 shift=1 pos="pos" no_first=true separator="|" class_text="pager_text" txt_pos="side"}

Die Suche hat {$result[0].num} Ergebnisse erbracht.<br><br><br>
<table width="100%" cellpadding="5" cellspacing="0" border="1">
{section name=idx loop=$result}
<tr class="oheader"><td colspan="2" height="35">Thema:&{$result[idx].topic_title}</td></tr>
<tr>
<td rowspan="2" valign="top" bgcolor="{cycle}">{$result[idx].poster}</td>
<td bgcolor="{cycle}">Forum:&{$result[idx].forum}&&Verfasst am:&{$result[idx].time}&&Titel:&{$result[idx].title}</td>
</tr>
<tr>
<td bgcolor="{cycle}">{$result[idx].posting}</td>
</tr>
{/section}
</table>


and it prints out what i wanted:


1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 26 | 36 | 46 | 56 | 66 | 76 | 86 | 96 | 106 Next

but when i go to page 2, my $result - Array is gone...normal?
how to do it?
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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