By: Maz
Date: 2006-08-13
Time: 02:28
|
Can't Get Pagination to Work Correctly
With the following code, the first set of records are showing correctly (Five records). However, after that, when clicking the paging links, I'm presented with a blank page. Can anyone see something I'm missing?
Demo of issue can be seen at: http://www.snippets.etomite.org/index.php?act=view_cat&id=5 where there are more than five records in the database.
CODE:
<?php
//----------------------------------------------------
// REQUIRED TEMPLATE PLUGINS FOR RECORD PAGINATION
//----------------------------------------------------
include_once ROOT_PATH."includes/plugins/tbs_plugin_bypage.php";
include_once ROOT_PATH."includes/plugins/tbs_plugin_navbar.php";
$kernel->validate_types($kernel->vars_request, array('id' => 'INT'));
$cat_titles = array();
$snippets = array();
$RecCnt = 0;
$PageSize = 5;
//----------------------------------------------------
// SETUP RECORD PAGING
//----------------------------------------------------
if (isset($kernel->vars_get['PageNum']))
{
$PageNum = intval($kernel->vars_get['PageNum']);
}
else
{
$PageNum = 1;
}
if (isset($kernel->vars_get['RecCnt']))
{
$RecCnt = intval($kernel->vars_get['RecCnt']);
}
else
{
$RecCnt = -1;
}
//----------------------------------------------------
// GET THE TITLE AND DESCRIPTION FOR THIS CATEGORY
//----------------------------------------------------
$query = "
SELECT
title,
description
FROM ".TBL_PREFIX."categories
WHERE cat_id = ".$kernel->vars_request['id']."";
$rst = $objDB->get_row($query, ARRAY_A);
$cat_titles['heading'] = $rst['title'];
$cat_titles['sub_heading'] = $rst['description'];
//----------------------------------------------------
// GET ARTICLES FOR PARENT CATEGORY
//----------------------------------------------------
$query = "
SELECT
title,
description,
article_id
FROM ".TBL_PREFIX."snippets
WHERE parent_cat = ".$kernel->vars_request['id']."";
$rst = $objDB->get_results($query, ARRAY_A);
if($objDB->num_rows > 0)
{
$snippets = $rst;
$RecCnt = $objDB->num_rows;
}
else
{
$RecCnt = 0;
}
//----------------------------------------------------
// PROCESS TEMPLATE
//----------------------------------------------------
$objTemplate->LoadTemplate($template_path.'public/view_cat.html');
$objTemplate->PlugIn(TBS_BYPAGE,$PageSize,$PageNum,$RecCnt);
$objTemplate->MergeField('cat_titles', $cat_titles);
$objTemplate->MergeBlock('snippet', $snippets);
$objTemplate->PlugIn(TBS_NAVBAR,'nv,nv2','',$PageNum,$RecCnt,$PageSize);
$objTemplate->Show();
?> |
TEMPLATE:
[onload;file=[var.template_path]global/header.html]
<h1>[cat_titles.heading]</h1>
<p id="subhead">[cat_titles.sub_heading]</p>
<div id="pagelinkstop">[onshow;block=div;when[var.RecCnt]]!=0]
<span class="pagefirst"><a href="[var..script_name]?act=view_cat&id=1&PageNum=[nv.first;endpoint;magnet=a;mtype=m+m]"><<</a></span>
<span class="pageprev"><a href="[var..script_name]?act=view_cat&id=1&PageNum=[nv.prev;endpoint;magnet=a;mtype=m+m]"><</a></span>
<span class="pagelink"><a href="[var..script_name]?act=view_cat&id=1&PageNum=[nv.page;block=span;navsize=3;navpos=centred]">[nv.page]</a></span>
<span class="pagecurrent">[nv.page;block=span;currpage]</span>
<span class="pagenext"><a href="[var..script_name]?act=view_cat&id=1&PageNum=[nv.next;endpoint;magnet=a;mtype=m+m]">></a></span>
<span class="pagelast"><a href="[var..script_name]?act=view_cat&id=1&PageNum=[nv.last;endpoint;magnet=a;mtype=m+m]">>></a></span>
</div>
[snippet;block=begin]
<h2><a href="#" onclick="showhide('art_[snippet.article_id]');">[snippet.title]</a></h2>
<div class="article-sub" id="art_[snippet.article_id]">
<p>[snippet.description]</p>
<p class="catlink"><a href="index.php?act=view_snippet&id=[snippet.article_id]">[var.kernel.lang.link_snipview]</a></p>
</div>
[snippet;block=end]
<div id="pagelinksbottom">[onshow;block=div;when [var.RecCnt]!=0]
<span class="pagefirst"><a href="[var..script_name]?PageNum=[nv2.first;endpoint;magnet=a;mtype=m+m]"><<</a></span>
<span class="pageprev"><a href="[var..script_name]?PageNum=[nv2.prev;endpoint;magnet=a;mtype=m+m]"><</a></span>
<span class="pagelink"><a href="[var..script_name]?PageNum=[nv2.page;block=span;navsize=3;navpos=centred]">[nv2.page]</a></span>
<span class="pagecurrent">[nv2.page;block=span;currpage]</span>
<span class="pagenext"><a href="[var..script_name]?PageNum=[nv2.next;endpoint;magnet=a;mtype=m+m]">></a></span>
<span class="pagelast"><a href="[var..script_name]?PageNum=[nv2.last;endpoint;magnet=a;mtype=m+m]">>></a></span>
</div>
[snippet;block=begin;nodata]
<h2>[var.kernel.lang.err_head_noarticles]</h2>
<p>[var.kernel.lang.err_noarticles;htmlconv=no]</p>
[snippet;block=end]
[onload;file=[var.template_path]global/footer.html] |
|