#include <infodrom.style>
#include <linx.style>
#include <db.style>
#include <phptools.inc>

<page title="Infodrom Linx" stylesheet="linx.css">
<linxtop>

<h3>Categories</h3>

<browser_with_tables>
<?
  $ch = "<linxcold>";
  $cd = "#ffffff";

  $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
               or die("Unable to connect to SQL server");

#  pg_exec ($dbh, "SET DateStyle = 'ISO'"); // ignore or die("Datenbank-Abfrage!");

  $query = "SELECT DISTINCT category FROM links ORDER BY category";
  $sth = pg_exec ($dbh, $query);

  $tables = browser_with_tables();
  $color = $cd;
  $category = "";
  if (pg_NumRows ($sth) > 0) {
    if (!$tables) {
      echo ("<ol>");
    } else {
      echo ('<table class="linx" border="0" cellspacing="0" cellpadding="2">'."\n");
    }
    for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
      $row = pg_fetch_array ($sth, $nr);

      $sthi = pg_exec($dbh, sprintf ("SELECT count(*) FROM links WHERE category = '%s'", $row['category']));
      if (pg_NumRows ($sthi) > 0) {
        $rowi = pg_fetch_array ($sthi, 0);
      } else {
        $rowi[0] = 0;
      }

      if (!$tables) {
	printf ("<li><a href=\"lookup.php?category=%s\">%s</a> (%d)", $row['category'], $row['category'], $rowi[0]);
      } else {
        $color = $color == $cd?$ch:$cd;
	printf ("<tr bgcolor=\"%s\"><td align=\"left\"><a href=\"lookup.php?category=%s\">"
	       ."<font face=\"<infodrom-font />\">%s</font></a></td>"
	       ."<td align=\"right\"><font face=\"<infodrom-font />\">%d</font></td></tr>",
	       $color, $row['category'], $row['category'], $rowi[0]);
      }
    }
    if (!$tables) {
      echo ("</ol>");
    } else {
      echo ("</table>");
    }
  }
?>


<linxbot>
</page>

# Local variables:
# mode: indented-text
# mode: auto-fill
# end:
