<?php

require_once("./functions.php");

PripojDb();

$iMaxLen = 20;

$sSql = "SELECT DISTINCT `ref` FROM `ref` ORDER BY `id` DESC LIMIT 100;";
$pRes = askDb($sSql);
if(mysqli_num_rows($pRes)) {
  echo "<table class=\"refs\">";
  $iCounter = 0;
  while($oRes = mysqli_fetch_object($pRes)) {
    if ($iCounter == 0) {
      echo "<tr>";
    }
    $iCounter++;
    $sDomena = $oRes->ref;
    if (strlen($sDomena) > $iMaxLen) {
      $sDomenaZkracena = substr($sDomena, 0, $iMaxLen) . "…";
    } else {
      $sDomenaZkracena = $sDomena;
    }
    echo '<td><a href="http://' . $sDomena . '/">' . $sDomenaZkracena . '</a></td>';
    if ($iCounter == 4) {
      echo "</tr>";
      $iCounter = 0;
    }
  }
  echo "</table>";
}

OdpojDb();

?>
