View previous topic :: View next topic |
Author |
Message |
renster Smarty n00b
Joined: 12 Jun 2003 Posts: 1
|
Posted: Thu Jun 12, 2003 1:17 pm Post subject: smarty_function_pager examples? |
|
|
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 |
|
Budda Smarty Regular
Joined: 19 Apr 2003 Posts: 53 Location: Lymm, Cheshire. UK
|
Posted: Wed Jun 18, 2003 2:16 pm Post subject: |
|
|
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
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 |
|
idxman01 Smarty Rookie
Joined: 10 Jun 2003 Posts: 14 Location: FL
|
Posted: Wed Jun 18, 2003 7:04 pm Post subject: |
|
|
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 |
|
Budda Smarty Regular
Joined: 19 Apr 2003 Posts: 53 Location: Lymm, Cheshire. UK
|
Posted: Thu Jun 19, 2003 8:14 am Post subject: |
|
|
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
stick that magic piece in and all offsets are shifted by 1. |
|
Back to top |
|
idxman01 Smarty Rookie
Joined: 10 Jun 2003 Posts: 14 Location: FL
|
|
Back to top |
|
Budda Smarty Regular
Joined: 19 Apr 2003 Posts: 53 Location: Lymm, Cheshire. UK
|
Posted: Thu Jun 19, 2003 12:57 pm Post subject: |
|
|
Does this mean that it still don't work? I can email you the 10k pager file if you wish? |
|
Back to top |
|
duda Smarty n00b
Joined: 02 Jul 2003 Posts: 2 Location: Budapest
|
|
Back to top |
|
idxman01 Smarty Rookie
Joined: 10 Jun 2003 Posts: 14 Location: FL
|
Posted: Thu Jul 03, 2003 5:20 am Post subject: |
|
|
Quote: | * Last Modified: July 7, 2003
|
Sweet.. Futureware.
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 |
|
risto Smarty Rookie
Joined: 26 Apr 2003 Posts: 21 Location: Norway
|
Posted: Fri Aug 29, 2003 7:37 pm Post subject: still not making sence |
|
|
what needs to be done to have the pager affect the array? it prints it all out anywhat! |
|
Back to top |
|
Budda Smarty Regular
Joined: 19 Apr 2003 Posts: 53 Location: Lymm, Cheshire. UK
|
Posted: Mon Sep 01, 2003 8:47 am Post subject: Re: still not making sence |
|
|
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" ? |
|
Back to top |
|
risto Smarty Rookie
Joined: 26 Apr 2003 Posts: 21 Location: Norway
|
Posted: Wed Sep 03, 2003 6:28 am Post subject: so effect |
|
|
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 |
|
risto Smarty Rookie
Joined: 26 Apr 2003 Posts: 21 Location: Norway
|
Posted: Wed Sep 03, 2003 8:37 am Post subject: lol |
|
|
forget it! forget it! |
|
Back to top |
|
pt2002 Smarty Regular
Joined: 05 May 2003 Posts: 89 Location: Porto, Portugal
|
Posted: Tue Sep 23, 2003 10:05 am Post subject: |
|
|
Hello
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 |
|
aholtzmann Smarty n00b
Joined: 20 Mar 2004 Posts: 1 Location: Houston, TX
|
Posted: Sat Mar 20, 2004 6:39 am Post subject: Updated pager Plugin |
|
|
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 |
|
Adar Smarty Regular
Joined: 27 May 2004 Posts: 58
|
Posted: Fri Jun 11, 2004 8:29 am Post subject: |
|
|
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 |
|
|