This function reurn a table showing:
$TagPage 2 $TagOf 23.......................1-2-3-4-5-6-7-8-9->>
example:
<?php
if($FoundCount > $NumRecs) echo
showPageNums("VisiList.php?usr=$usr&zon=$zon&nom=$nom&tc=$tc",$NumRecs,$FoundCount,$SkipNumber,'Page','of');
?>
code:
<?php
####################################################################
function showPageNums($href,$ShownByPage,$FoundCount,$LastSkip,$TagPage,$TagOf) {
####################################################################
mostra en una taula justificada al 100% quelcom semblant a:
Pàgina 13 d'un total de 32 <- 11 12 13 14 15 16 17 18 19 20 ->
utilitzar les clases d'estil 'PageLink' i 'PageNum' per personalitzar l'aspecte
href = url+parametres que es fa servir per mostrar les planes de resultats
ShownByPage = nº d'items mostrats per plana
FoundCount = nº d'items totals
LastSkip = nº d'items que ens saltem
TagPage = un missatge tal com 'Pàgina' segons exemple
TagOf = un missatge tal com 'd'un total de' segons exemple
$s='';
if($FoundCount >0) {
$LinksShown = 10;
$ShownPage = $LastSkip/$ShownByPage + 1;
$FirstPage = ( (int) (($ShownPage - 1) / $ShownByPage)) * $ShownByPage + 1;
$LastPage = min(($FirstPage + $LinksShown - 1),ceil($FoundCount/ (double) $ShownByPage));
$SkipNumber = $FirstPage * $ShownByPage - $ShownByPage;
$Resto = $FoundCount % $ShownByPage;
$i = ($Resto>0)? 1:0;
$TotalPages = (int) ($FoundCount / $ShownByPage) + $i;
$s="<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH='100%'>
<TR>
<TD>
<font class='PageNum'>
$TagPage $ShownPage $TagOf $TotalPages
</font>
</TD>
<TD align=right>
<font class='PageLink'>";
if($SkipNumber > 0) $s .= "<a class='PageLink' href='$href&FoundCount=$FoundCount&SkipNumber=". ($SkipNumber-$ShownByPage) ."'><<</a> ";
for ($n = $FirstPage; $n <= $LastPage; $n++) {
if($n == $ShownPage) {
$s .="<font class=PageLink>$n</font> ";
}
else {
$s .= "<a class=PageLink href='$href&FoundCount=$FoundCount&SkipNumber=$SkipNumber'>$n</a> ";
}
$SkipNumber += $ShownByPage;
}
if($SkipNumber<$FoundCount) $s .= "<a class=PageLink href='$href&FoundCount=$FoundCount&SkipNumber=$SkipNumber'>>></a>";
$s .= " </font>
</TD>
</TR>
</TABLE>";
}
return $s;
}
?>
Hope this helps,
joan
Louie wrote:
If you are familiar with the LIMIT feature in MySQL(this is what you are using I presume) you just need to do a prelim query, I would suggest using the count(*) function to get the total number of records you will be dealing with. Then you need to determine how many records you want to display per page. You can then divide your total records by your records per page to get how the number of pages. You can use a for statement to create the links each with the offset number appenede to the end. ie:
For 15 records per page:
<a href="<?php print $PHP_SELF; ?>?offset=15">2</a>
<a href="<?php print $PHP_SELF; ?>?offset=30">3</a> and so on...
then your select statement would look like
"SELECT * from tablename WHERE something = 'something' LIMIT, $offset, ($offset + 15)"
Hope that helps there is also a great column on this site about it, that is where I learned how to do it