diff --git a/public/harjoittelupaikat.php b/public/harjoittelupaikat.php
index 9590ca9..f8366df 100644
--- a/public/harjoittelupaikat.php
+++ b/public/harjoittelupaikat.php
while($row = $result->fetch_assoc()) {
$harjoittelupaikat[] = $row;
}
- } else {
- echo "Harjoittelupaikkoja ei löytynyt";
}
$conn->close();
</h1>
<a href="../public/uusharjoittelupaikka.php"><button>Lisää harjoittelupaikka</button></a>
<main>
- <div class="table-container">
- <table>
- <thead>
- <tr>
- <th>Nimi</th>
- <th>Ohjaaja</th>
- <th>Yhteystiedot</th>
- <?php // Ei muokkaus riviä, jos ei ole oikeuksia muokata
- if ($logged_in)
- {
- echo "<th>Muokkaus</th>";
- }
- ?>
- </tr>
- </thead>
- <tbody>
- <?php
- foreach ($harjoittelupaikat as $harjoittelupaikka) {
- if (isset($_GET['id']) and $harjoittelupaikka['id'] === $_GET['id']) { // Muokataan
- // Kopioitu index.php:stä, siellä on lisää kommentteja
- echo "<form action='../src/muokkaa.php' method='POST'>";
- echo "<input type='hidden' id='taulukko' name='taulukko' value=harjoittelupaikat>";
- echo "<input type='hidden' id='id' name='id' value={$harjoittelupaikka['id']}>";
- echo "<td> <input type='text' name='nimi' id='nimi' value='" . $harjoittelupaikka["nimi"] . "'> </td>";
- echo "<td> <input type='text' name='ohjaaja' id='ohjaaja' value='" . $harjoittelupaikka["ohjaaja"] . "'> </td>";
- echo "<td> <input type='text' name='yhteystiedot' id='yhteystiedot' value='" . $harjoittelupaikka["yhteystiedot"] . "'> </td>";
- echo "<td> <button type='submit'>Tallenna muutokset</button></td>";
- echo "</form>";
+ <?php if (!empty($harjoittelupaikat)): ?>
+ <div class="table-container">
+ <table>
+ <thead>
+ <tr>
+ <th>Nimi</th>
+ <th>Ohjaaja</th>
+ <th>Yhteystiedot</th>
+ <?php // Ei muokkaus riviä, jos ei ole oikeuksia muokata
+ if ($logged_in)
+ {
+ echo "<th>Muokkaus</th>";
}
- else { // Ei muokata
- echo "<tr>";
- echo "<td>" . $harjoittelupaikka["nimi"] . "</td>";
- echo "<td>" . $harjoittelupaikka["ohjaaja"] . "</td>";
- echo "<td>" . $harjoittelupaikka["yhteystiedot"] . "</td>";
- if ($op) { // Jos opettaja tai muokkaa omia tietoja
- echo "<td class='muokkaus-column'>" . // Poista nappi
- "<form action='../src/poista.php' method='POST'>
- <input type='hidden' id='nimi' name='nimi' value={$harjoittelupaikka['nimi']}>
- <input type='hidden' id='taulukko' name='taulukko' value=harjoittelupaikat>
- <button type='submit'>Poista</button>
- </form>";
- echo "" . // Muokkaa nappi
- "<form action='../public/harjoittelupaikat.php?id={$harjoittelupaikka['id']}' method='GET'>
- <input type='hidden' id='id' name='id' value={$harjoittelupaikka['id']}>
- <button type='submit'>Muokkaa</button>
- </form>"
- . "</td>";
- }
- echo "</tr>";
+ ?>
+ </tr>
+ </thead>
+ <tbody>
+ <?php
+ foreach ($harjoittelupaikat as $harjoittelupaikka) {
+ if (isset($_GET['id']) and $harjoittelupaikka['id'] === $_GET['id']) { // Muokataan
+ // Kopioitu index.php:stä, siellä on lisää kommentteja
+ echo "<form action='../src/muokkaa.php' method='POST'>";
+ echo "<input type='hidden' id='taulukko' name='taulukko' value=harjoittelupaikat>";
+ echo "<input type='hidden' id='id' name='id' value={$harjoittelupaikka['id']}>";
+ echo "<td> <input type='text' name='nimi' id='nimi' value='" . $harjoittelupaikka["nimi"] . "'> </td>";
+ echo "<td> <input type='text' name='ohjaaja' id='ohjaaja' value='" . $harjoittelupaikka["ohjaaja"] . "'> </td>";
+ echo "<td> <input type='text' name='yhteystiedot' id='yhteystiedot' value='" . $harjoittelupaikka["yhteystiedot"] . "'> </td>";
+ echo "<td> <button type='submit'>Tallenna muutokset</button></td>";
+ echo "</form>";
+ }
+ else { // Ei muokata
+ echo "<tr>";
+ echo "<td>" . $harjoittelupaikka["nimi"] . "</td>";
+ echo "<td>" . $harjoittelupaikka["ohjaaja"] . "</td>";
+ echo "<td>" . $harjoittelupaikka["yhteystiedot"] . "</td>";
+ if ($op) { // Jos opettaja tai muokkaa omia tietoja
+ echo "<td class='muokkaus-column'>" . // Poista nappi
+ "<form action='../src/poista.php' method='POST'>
+ <input type='hidden' id='nimi' name='nimi' value={$harjoittelupaikka['nimi']}>
+ <input type='hidden' id='taulukko' name='taulukko' value=harjoittelupaikat>
+ <button type='submit'>Poista</button>
+ </form>";
+ echo "" . // Muokkaa nappi
+ "<form action='../public/harjoittelupaikat.php?id={$harjoittelupaikka['id']}' method='GET'>
+ <input type='hidden' id='id' name='id' value={$harjoittelupaikka['id']}>
+ <button type='submit'>Muokkaa</button>
+ </form>"
+ . "</td>";
+ }
+ echo "</tr>";
+ }
}
- }
- ?>
- </tbody>
- </table>
- </div>
+ ?>
+ </tbody>
+ </table>
+ </div>
+ <?php else: ?>
+ <p>Harjoittelupaikkoja ei löytynyt</p>
+ <?php endif; ?>
</main>
<?php include "../src/footer.php"; ?>
</body>