Categories > TinyButStrong general >

Regarding Display by page...

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: robee
Date: 2003-08-19
Time: 04:28

Regarding Display by page...

hi! i've tried ur display by page code and it;s working. However, when I tried to adopt mr.guzi's code regarding <Prev 123 Next> paging i cant make it run properly...here's how I did it..

datasql.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SERIAL MANAGEMENT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="tbs_us_examples_0styles.css" rel="stylesheet" type="text/css">
</head>

<body>
<p align="center" class="title-page">Serial Results</p>
<table border="1" align="center" cellpadding="2" cellspacing="0">
  <tr bgcolor="#CACACA">
    <td width="50"><strong>HoldingsID</strong></td>
    <td width="150"><strong>Title</strong></td>
    <td width="50"><strong>AgencyCode</strong></td>
    <td width="100"><strong>MaterialType</strong></td>
  </tr>
  <tr bgcolor="#F0F0F0">
    <td>[blk.HoldingsID;block=row]</td>
    <td>[blk.Title;block=row]</td>
    <td> <div align="right">[blk.AgencyCode;block=row]</div></td>
    <td> <div align="center">[blk.MaterialType;block=row]</div></td>
  </tr>
  <tr bgcolor="#E6E6E6">
    <td>[blk.HoldingsID;block=row]</td>
    <td>[blk.Title;block=row]</td>
    <td> <div align="right">[blk.AgencyCode;block=row]</div></td>
    <td><div align="center">[blk.MaterialType;block=row]</div></td>
  </tr>
</table>
<p align="center">There are [blk.#] displayed lines.</p>
<p align="center">Number of products: [var.reccnt]</p>
<table border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="50" valign="top">
      <div align="left">Page : </div></td>
    <td width="20" valign="top">
      <div align="center"><a href="datasql.php?PageNum=[pg.#]&RecCnt=[var.RecCnt]">[pg.#;block=td]</a><br>
        [var.PageNum;if [val]=[pg.#];then '*' ;else '']</div></td>
  </tr>
</table>
<table><tr><td>
  <a href="datasql.php?page=[nav.key;block=td]">[nav.val]</a>
</td></tr><table>
</body>
</html>


and here's where I call this template
datasql.php

include_once("tbs_class.php") ;

//Connexion to the database
require('DB.php');

function  m_getlinks($PageNum, $width, $page_nbr = 0)
{
    $links = array();
    $page_min = $PageNum - ($PageNum % $width) + 1 ;
    $page_max = $page_min + $width - 1 ;
    if($page_nbr > 0)
        $page_max = min($page_max, $page_nbr);
    if($page_min > 1)
        $links[$page_min-5] = ' << ';
    for($i = $page_min; $i <= $page_max; $i++)
        $links[$i] = $i;
    if($page_nbr > $page_max)
        $links[$page_max+1] = ' >> ';
    return $links;
}
//Default value
if (array_key_exists("PageNum",$_GET)) {
  $PageNum = $_GET["PageNum"] ;
} else {
    $PageNum = 1 ;
} ;

//Default value
if (array_key_exists("RecCnt",$_GET)) {
  $RecCnt = intval($_GET["RecCnt"]) ;
} else {
    $RecCnt = -1 ;
} ;

$PageSize = 20 ;

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate("datasql.htm") ;

//Merge the block by page
$RecCnt = $TBS->MergeBlock("blk",$cnx_id,"SELECT * FROM tblHoldings where AgencyCode='SEI'",$PageSize,$PageNum,$RecCnt) ;
//Calculate the number of page
$PageCnt = ceil($RecCnt / $PageSize) ;
//Display the list of pages
$TBS->MergeBlock("pg","num",$PageCnt) ;

$links = m_getlinks($PageNum,10,$page_nbr) ;
$TBS->MergeBlock("nav",$links) ;


$TBS->Show() ;


mysql_close($cnx_id) ;
$TBS->Show() ;


i've got 10, 000 records per page load...and I need to display the records, 20 per page so it wont mess my page...can anyone help me out?..
By: Skrol29
Date: 2003-08-20
Time: 16:26

Re: Regarding Display by page...

Hello Robee,

First little remarks about the syntax:

HTML :
- you missed a closing tag for the table which embeds the "nav" block.
Replace <table> with </table> (I love Dreamweaver).
- You don't need to repeat the parameter "block=row" for each fields of the row. Only one per row is enought. For example, choose keep the first.

PHP :
- in the function m_getlinks(), the code
  ... $links[$page_min-5] = ... is very suspect.
It should be
  ... $links[$page_min-1] = ...
or
  ... $links[$page_min-$width] = ...

Let me know if it works better after that.