Add a paging facility
authorJoey Schulze <joey@infodrom.org>
Thu, 17 May 2007 16:50:23 +0000 (16:50 +0000)
committerJoey Schulze <joey@infodrom.org>
Thu, 17 May 2007 16:50:23 +0000 (16:50 +0000)
src/Infodrom/logbook/index.wml

index 0d17274..3d259a5 100644 (file)
@@ -9,12 +9,15 @@
 <th width=80%>Titel</th></tr>
 
 <?
+  $limit = 50;
   $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
               or die("Unable to connect to SQL server");
 
   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
 
-  $query = "SELECT id,teaser,category,created FROM logbook ORDER BY created DESC LIMIT 50";
+  $query = "SELECT id,teaser,category,created FROM logbook ORDER BY created DESC LIMIT $limit";
+  if (isset ($_GET["offset"]))
+    $query .= sprintf (" OFFSET %d\n", $_GET["offset"]);
   $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
 
   for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
     printf ("<tr><td align=\"right\">%s</td><td align=\"center\">%s</td><td><a href=\"show.php?id=%s\">%s</a></td></tr>",
           $date, $row['category'], $row['id'], $row['teaser']);
   }
-?>
 
-</table>
+  echo ("</table>\n");
+
+  if ($nr >= pg_NumRows ($sth)) {
+    printf ("<p><a href=\"index.php?offset=%d\">next</a></p>\n", $_GET["offset"]+$limit);
+  }
+?>
 
 </page>