<?php

require "db.php";

echo "<a href=crud.php?action=create>Vytvořit nový záznam</a><br><br>";
try {
    $sql = "SELECT id, barva FROM barvy";
    // Execute the SQL query
    $result = $conn->query($sql);
    // Process the result set
    if ($result->rowCount() > 0) {

      echo "<table border=1><tr><th>ID</th><th>Barva</th><th>Operace</th></tr>";
      // Output data of each row
      while($row = $result->fetch()) {
        echo "<tr>";
        echo "<td>" . $row['id'] . "</td>";
        echo "<td>" . $row['barva'] . "</td>";
        echo "<td>
        <a href=\"crud.php?action=edit&id={$row['id']}\">Editovat</a>
        <a href=\"crud.php?action=delete&id={$row['id']}\">Vymazat</a>
        </td>";
        echo "</tr>";
      }
      echo "</table>";
      unset($result);
    }
    else {
      echo "No records found.";
    }
  } catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
  }






?>