RE: Help: Next/Prev in query results
| From: | Joris Trooster / Interstroom | Date: | Thu, 21 Feb 2002 17:17:09 +0000 |
| Subject: | RE: Help: Next/Prev in query results | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2816@lists.php.net to get a copy of this message | ||
Jorge,
Just a quick example below for a database query. I did not test the code
below, but it should be something like this.
Edit/tune for your own needs.
Regards,
Joris
PHP code:
// Max items per page
$maxresults = 10;
// Use your own database class/functions, this example will probably not
work for you
$number = NumSQLRows("SELECT * FROM table");
if ($page < 0) $page = 0;
$offset = (int)$page * $maxresults;
$lastpage = ceil( $number / $maxresuls );
// The limit...
$limit = "LIMIT ".$offset.",".$maxresults;
// The query
// Use your own database class/functions, this example will probably not
work for you
$smarty->assign("resultarray", SQLArray("SELECT * FROM table ".$limit));
$smarty->assign("page", $page);
$smarty->assign("nextpage", ($page < $lastpage) ? $page : "");
$smarty->assign("prevpage", ($page > 0) ? $page : "");
$smarty->assign("lastpage", $lastpage);
Smarty template:
{section name=row loop=$resultarray}
{* result number *}
{math equation="iteration + (page * numrows)" iteration=%row.iteration%
page=$page numrows=$maxresults}.
.....
{/section}
{if $prevpage}<A
href="{$SCRIPT_NAME}?&page={$lastpage}">previous</A>{/if}
{if $nextpage}<A href="{$SCRIPT_NAME}?&page={$nextpage}">next</A>{/if}
> > I wonder if someone can enlighten me in how to put prev/next
> > buttons when
> > showing database query results in html tables, using Smarty.
> >
> > If someone can share any code, it would be a good help.
> >
> > Any help will be apreciated.
> >
> > :)
> >
> > Jorge