Categories > TinyButStrong general >

Odd Pagination Problem

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Maz
Date: 2006-05-30
Time: 22:39

Odd Pagination Problem

Code:

    require_once('includes/init.inc.php');

    //---------------------------------------------
    // Write Meta Data
    //---------------------------------------------
    $page_data     = array(
        'title' => 'Download IPB Skins, Mods, and Graphics for Invision Power Board',
        'desc'     => 'Browse the InvisionCube IPB skins, mods, and graphics database');

    //---------------------------------------------
    // Include Required Files
    //---------------------------------------------
    include_once APP_CLASS_PATH."tbs_plugin_bypage.php";
    include_once APP_CLASS_PATH."tbs_plugin_navbar.php";
    include_once APP_CLASS_PATH."tbs_plugin_html.php";
   
    //---------------------------------------------
    // Initialise variables
    //---------------------------------------------
    $sidebar    = 'sb_public';
    $category     = 2;
    $products     = array();
    $subcats     = array();

    //---------------------------------------------
    // Has skin browsing been disabled?
    //---------------------------------------------
    if (!$icube->settings['skinbrowse_enabled'])
    {
        $err_msg = $lang['err_module_disabled'];
        $FuncExec->show_error($err_msg);
    }
   
    //---------------------------------------------
    // Setup Record Paging
    //---------------------------------------------
   
    if (isset($icube->vars_get['PageNum']))
    {
        $PageNum = intval($icube->vars_get['PageNum']);
    }
    else
    {
        $PageNum = 1;
    }
   
    if (isset($icube->vars_get['RecCnt']))
    {
        $RecCnt = intval($icube->vars_get['RecCnt']);
    }
    else
    {
        $RecCnt = -1;
    }
   
    $PageSize = 2;

    /* $validate->validate_types($icube->vars_get, array('cat' => 'INT', 'sub' => 'INT'));
   
    if (isset($_GET['cat']) && !empty($_GET['cat']))
    {
        $category = $_GET['cat'];
    }
   
    if (isset($icube->vars_post['lst_subs']) && !empty($icube->vars_post['lst_subs']))
    {
        $sub_category = intval($icube->vars_post['lst_subs']);
    }*/
   
    //------------------------------------------------
    // Get Product Records
    //------------------------------------------------   
    $query = "
    SELECT    
        p.author,
        p.product_id,
        p.title,
        p.description,
        f.file_title as thumb
    FROM ".INV_PREFIX."products p
    LEFT OUTER
        JOIN ".IPB_PREFIX."members m
    ON m.id=p.author
    LEFT OUTER
        JOIN ".INV_PREFIX."product_files f
    ON f.file_id = p.product_id
    AND f.file_type = 'image'
    AND f.file_index = 1
    WHERE p.product_state = 4
    AND p.is_hidden = 0
    AND p.category = ".$category."
    GROUP BY p.title
    ORDER BY p.timestamp DESC";

     $rst = $objDB->get_results($query, ARRAY_A);
    
    if($objDB->num_rows > 0)
    {
        $products = $rst;
    }

    //---------------------------------------------
    // Create and Populate Sub Cats List Array
    //---------------------------------------------
    /*$query = "
        SELECT id, title
        FROM ".INV_PREFIX."product_categories
        WHERE parent_id = ".$category."
    ";
   
    $rst = $objDB->get_results($query, ARRAY_A);
   
    if($objDB->num_rows > 0)
    {
        $lst_subs = $rst;
    }*/
   
    $TBS->LoadTemplate($template_path.'content/modules/products/browse.html');
   
    $TBS->PlugIn(TBS_BYPAGE,$PageSize,$PageNum,$RecCnt);
    $TBS->MergeBlock('product',$products);
    $TBS->PlugIn(TBS_NAVBAR,'nv,nv2','',$PageNum,$RecCnt,$PageSize);
    $TBS->Show();

I have checked the above code, in particular the number of records it's returning, and there are three records returned. So far, so good. Note too that I have the PageSize variable set to 2, so there should be two paging links, correct? The first page showing two records, and the second page, showing the one remaining record.

However, what I get are three paging links. On the first page, it shows the correct two records, on the second page, the remaining one, and then on the third page (which shouldn't be there anyway) it shows nothing.

Template:

[onload;file=[var.template_path]layout/header.html]
<h1>Download Unique Invision Skins</h1>
<!--<form action="[var..script_name]" id="subs" method="post">
    <fieldset class="alignright">
        <label for="lst_subs">Sub Categories: </label>
        <select class="select" name="lst_subs" id="lst_subs" tabindex="1" style="width: 17em;">
            <option value="[lst_subs.id]">[lst_subs.title;block=option]</option>
        </select>
        <input type="submit" value="Go" />
    </fieldset>
</form>
<br />-->
<div id="pagelinkstop">   
    <span class="pagefirst"><a href="[var..script_name]?PageNum=[nv.first;endpoint;magnet=a;mtype=m+m]">&lt;&lt;</a></span>
    <span class="pageprev"><a href="[var..script_name]?PageNum=[nv.prev;endpoint;magnet=a;mtype=m+m]">&lt;</a></span>
    <span class="pagelink"><a href="[var..script_name]?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]?PageNum=[nv.next;endpoint;magnet=a;mtype=m+m]">&gt;</a></span>
    <span class="pagelast"><a href="[var..script_name]?PageNum=[nv.last;endpoint;magnet=a;mtype=m+m]">&gt;&gt;</a></span>
</div>   
[product;block=begin]
<h2>[product.title]</h2>
<div class="product-box">
    [product.thumb;if [val]='';then '<img src="[var.icube.settings.img_dir]nothumb.png"
    alt="[lang.alt_no_shot]" title="[lang.alt_no_shot]" height="[var.icube.settings.img_theight]" width="[var.icube.settings.img_twidth]" />';else '<img class="fancyimg" src="[var.icube.settings.img_dir][var.icube.settings.img_tprefix][product.thumb]" alt="[product.title] screenshot" title="[product.title] screenshot" height="[var.icube.settings.img_theight]" width="[var.icube.settings.img_twidth]" />']
    <div class="product-details">
        <p class="product-desc">[product.description;ope=max:80]</p>
        <ul class="related">
            <li><a href="[var.abs_root]source/products/product-info.php?pid=[product.product_id]">In-Depth Product Details</a></li>           
    [product.thumb;if [val]!='';then '<li><a href="[var.icube.settings.img_dir][product.thumb]">View Large Screenshot</a></li>']
        </ul>
        <div class="clearer"></div>
    </div>
</div>
[product;block=end]
<div id="pagelinksbottom">   
    <span class="pagefirst"><a href="[var..script_name]?PageNum=[nv2.first;endpoint;magnet=a;mtype=m+m]">&lt;&lt;</a></span>
    <span class="pageprev"><a href="[var..script_name]?PageNum=[nv2.prev;endpoint;magnet=a;mtype=m+m]">&lt;</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]">&gt;</a></span>
    <span class="pagelast"><a href="[var..script_name]?PageNum=[nv2.last;endpoint;magnet=a;mtype=m+m]">&gt;&gt;</a></span>
</div>
[onload;file=[var.template_path]layout/footer.html]
By: Maz
Date: 2006-05-30
Time: 22:51

Re: Odd Pagination Problem

I *think* I've solved it again, right after posting! lol

By changing:

    if($objDB->num_rows > 0)
    {
        $products = $rst;
    }

to:

    if($objDB->num_rows > 0)
    {
        $products = $rst;
        $RecCnt = $objDB->num_rows;
    }

Though oddly, I'm building another site and I don't populate the $recCnt variable there, but it works just fine.

Can you clarify this, Skrol, as it has me confused as to why it works on one site, but isn't needed on another.