Categories > TinyButStrong general >

Paginating output in tbs1.81

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: AL
Date: 2004-03-17
Time: 16:55

Paginating output in tbs1.81

Hi Skrol:

Im developing with tbs1.81, and didnt consider upgrading (since i've got to fix it to work on my php4.1.2-6woody3 and dunno if a newer version will work) but i've found a problem with pages and can't get rid of it (so if it can be fixed by upgrading to a newer tbs.. ill need to rewrite the code related to cloneblocks?).

The issue is:

im coding a download collection, which displays the path to current categories, all nested categories and finally the download items in the current level (these are paginated). I've took the code from the examples, with some minor changes and it works by getting just one parm from the url: the page you want to see, like (stripped template follows)

<table>
    <tr>
        <td width="80" valign="top">
            <div align="left">P&aacute;gina: </div></td>
    <td width="20" valign="top">
        <div align="center">
        <a href="download.php?id=[var.id]&par1=[pg.#]">[pg.#;block=td]</a>
        <br>
        [var.PaginaNum;if [val]=[pg.#];then '^' ;else '']
        </div>
    </td>
    </tr>
</table>

where var.id is just the category to be listed. On the PHP side we have:

//...
if (array_key_exists("par1",$_GET)) {
  $PaginaNum = $_GET["par1"] ;
} else {
    $PaginaNum = 1 ;
}
$CuentaReg = -1 ;
$ElemPorPag = 4 ;
//...more code here to get the path, cats and subcats,
//and fetch properties from each file (format,size,lastchange,etc)

$CuentaReg = $TBS->MergeBlock("descargas",$descarga,"",$ElemPorPag,$PaginaNum,$CuentaReg) ;
//Calculate how many pages..
$Paginas = ceil($CuentaReg / $ElemPorPag) ;
//Replace numbers
$TBS->MergeBlock("pg","num",$Paginas) ;

Everithing works fine except for the par1 parameter.. if i manually change its value on the url putting something higher than the possible number of pages, it hangs ' til reaches the max_execution_time defined on php.ini. The question is where should i validate the PageNum against RecKnown/PageSize to avoid this situation?

I'm thinking of paginate many other listings with this tecnique and if my code is correct, i wish to patch tbs for future similar uses.

Best Regards
By: Skrol29
Date: 2004-03-17
Time: 22:39

Re: Paginating output in tbs1.81

>ill need to rewrite the code related to cloneblocks?)

No Clone-blocks work the same (no code changed), but now they are called sub-block in the manual because this is much more understood.
You can refere to the Change Log to see what have changed. I signal each change that can make a compatibility problem.
By: Skrol29
Date: 2004-03-17
Time: 22:41

Re: Paginating output in tbs1.81

TBS 1.9x is compatible with  php>= 4.0.4 so  php 4.1.2 is ok.
By: Skrol29
Date: 2004-03-17
Time: 22:51

Re: Paginating output in tbs1.81

> The question is where should i validate the PageNum
> against RecKnown/PageSize to avoid this situation?

As I remember, if your are going to far in the number of page it shouldn't be such a problem and TBS should display an block with no data.
But anyway, it is better to calculate the real number of page yourself, in order to be sure that you are not going to far. The version of tbsForum you have with TBS 1.81 is doing that.

At that first visit on the page, you get the number of record and then calculate the number of page. For the next visit on the same catgey, you give the number of record in the url.
By: AL
Date: 2004-03-18
Time: 19:20

Re: Paginating output in tbs1.81

Thanks for your support. I'm upgrading tbs right now.. i've just missed the changelog.