Paging
| From: | Richard Watt | Date: | Thu, 12 Dec 2002 10:10:44 +0000 |
| Subject: | Paging | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-6743@lists.php.net to get a copy of this message | ||
Ignore that last thread about errors, I managed to fix it (I was making
calls to a function on one of my classes that messed things up). Next
question is regarding paging tables.
I have managed to do a multipage output of an array using only smarty,
but it makes rather a lot of use of the {math} function, which I realise
is not very efficient. Is there any way of doing this more efficiently
(I know there is a custom paging function I can download, but I would
prefer to do this in Smarty as I need a bit more than that function
provides)?
{section name=styles loop=$mystyle max=#recordsPerPage# start=
$smarty.get.offset|default:0}
{if $smarty.section.styles.first}
<table class="table_content">
<tr>
<th>
Name
</th>
<th>
Directory
</th>
<th>
Description
</th>
</tr>
{/if}
<tr>
<td class="{cycle values="rowlight,rowdark" advance=false}">
{$mystyle[styles].styleName}
</td>
<td class="{cycle advance=false}">
{$mystyle[styles].styleDirectory}
</td>
<td class="{cycle}">
{$mystyle[styles].styleDescription}
</td>
</tr>
{if $smarty.section.styles.last}
<tr>
<td colspan="3">
{capture name=maxrecords}{math equation="x + y" x=
$smarty.get.offset|default:0 y=#recordsPerPage#}{/capture}
{capture name=lastpage}{math equation="x - y" x=$records
y=#recordsPerPage#}{/capture}
{$smarty.capture.lastpage}
Viewing records {math equation="x + 1" x=
$smarty.get.offset|default:0}-{if $records gte
$smarty.capture.maxrecords}{$smarty.capture.maxrecords}{else}{$records}
{/if} of {$records}
<BR>
{if $smarty.get.offset ne 0}<a href="./admin.php?p=style&offset=0">
<<</a>{/if}
{if $smarty.get.offset ne 0}<a href="./admin.php?p=style&offset=
{math equation="x - y" x=$smarty.get.offset|default:0
y=#recordsPerPage#}"><</a>{/if}
{if $smarty.get.offset ne $smarty.capture.lastpage}<a
href="./admin.php?p=style&offset={math equation="x + y" x=
$smarty.get.offset|default:0 y=#recordsPerPage#}">></a>{/if}
{if $smarty.get.offset ne $smarty.capture.lastpage}<a
href="./admin.php?p=style&offset={$smarty.capture.lastpage}">>></a>{/if}
</td>
</tr>
</table>
{/if}
{sectionelse}
<table class="table_content">
<tr>
<th>
There are no records, sorry.
</th>
</tr>
{/section}