[SOLVED]Almost got it.. pagination (please advice)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pookie62
Forum Commoner
Posts: 92
Joined: Tue Dec 07, 2004 2:44 pm

[SOLVED]Almost got it.. pagination (please advice)

Post by pookie62 »

Hi All,
I'm a newby with PHP and got a piece of code which I can't get right..
There are no links to next pages created and I can't get it to work although I'v e been reading a lot here.. Please have a look at the code:
Thanks in advance !!

Code: Select all

<?php
<?php
$maxRows_Comp = 20;
$pageNum_Comp = 0;
if (isset($_GET['pageNum_Comp'])) {
  $pageNum_Comp = $_GET['pageNum_Comp'];
}
$startRow_Comp = $pageNum_Comp * $maxRows_Comp;
?>
<font size="+4" color="#CCCCCC"<strong>Competitie standen ASN 2005</strong></font>
<?php
   /* Connecting, selecting database */
$link = mysql_connect("XXX", "xxxx", "xxxx")
    or die("Could not connect : " . mysql_error());
mysql_select_db("ASN") or die("Could not select database");

$query_Comp = "SELECT 
  `klasse`.`Klasse` AS `Klasse`,
  `klassement`.`LevelId` AS `Level`,
  `deelnemer`.`Naam` AS `naam`,
  `deelnemer`.`Vereniging` AS `Vereniging`,
  TRUNCATE (`klassement`.`Totaal percentage` * 100, 2) AS `Totaal%`,
  TRUNCATE (`klassement`.`Gemiddelde percentage` * 100,2) AS `Gem%`
FROM
  `klassement`
  INNER JOIN `deelnemer` ON (`klassement`.`DeelnemerId` = `deelnemer`.`Id`)
  INNER JOIN `deelnemerklasselevel` ON (`deelnemer`.`Id` = `deelnemerklasselevel`.`DeelnemerId`)
  INNER JOIN `klasse` ON (`klassement`.`KlassId` = `klasse`.`Id`)
GROUP BY `Klasse`,`Naam`,`Level`
ORDER BY `Klasse`,`Level`,`Totaal Percentage` DESC";
$query_limit_Comp = sprintf("%s LIMIT %d, %d", $query_Comp, $startRow_Comp, $maxRows_Comp);
$Comp = mysql_query($query_limit_Comp, $link) or die(mysql_error());
$row_Comp = mysql_fetch_assoc($Comp);

if (isset($_GET['totalRows_Comp'])) {
  $totalRows_Comp = $_GET['totalRows_Comp'];
} else {
  $all_Comp = mysql_query($query_Comp);
  $totalRows_Comp = mysql_num_rows($all_Comp);
}
$totalPages_Comp = ceil($totalRows_Comp/$maxRows_Comp)-1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ASN Competitie</title>
<style type="text/css">
<!--
.style3 {
	font-size: 14pt;
	font-weight: bold;
}
-->
</style>
</head>
<body>
<table width="61%" border="1">
  <tr>
    <td width="7%"><span class="style3">Klasse</span></td>
    <td width="7%"><strong class="style3">Level</strong></td>
    <td width="17%"><strong class="style3">Naam</strong></td>
	<td width="22%"><strong class="style3">Vereniging</strong></td>
    <td width="14%"><strong class="style3">Totaal %</strong></td>
    <td width="11%"><strong class="style3">Gem % </strong></td>
    
  </tr>
  <?php do { ?>
  <tr>
    <td><?php echo ucfirst($row_Comp['Klasse']); ?></td>
    <td><?php echo htmlentities($row_Comp['Level']); ?></td>
    <td><?php echo ucfirst($row_Comp['naam']); ?></td>
	<td><?php echo htmlentities($row_Comp['Vereniging']); ?></td>
    <td><?php echo $row_Comp['Totaal%']; ?></td>
    <td><?php echo $row_Comp['Gem%']; ?></td>
    
  </tr>
  <?php } while ($row_Comp = mysql_fetch_assoc($Comp)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Comp);
?>
?>
Last edited by pookie62 on Wed Dec 08, 2004 12:40 am, edited 1 time in total.
User avatar
potsed
Forum Commoner
Posts: 50
Joined: Sat Oct 09, 2004 12:00 pm
Location: - South Africa

Post by potsed »

I answered a similar post here
viewtopic.php?p=146856#146856

The final script works.. just modify the sql queries and db login info and the output...
pookie62
Forum Commoner
Posts: 92
Joined: Tue Dec 07, 2004 2:44 pm

Post by pookie62 »

Oke Potsed, thanks !
Going to work this out..

Back again..
Working out great !! Thanks very muchos..!!
(I love this board..)
Last edited by pookie62 on Wed Dec 08, 2004 12:43 am, edited 1 time in total.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Pagination boils down to some simple arithmetic using:

- total rows (eg from mysql_num_rows)
- rows displayed per page (set a config constant or whatever)
- the requested page number (from $_GET probably)

Not much more to it really.
Post Reply