Diff between 60a27216ca7a1f3d6768c541b77c9e616f4a092a and de7829453c715b6d7995224dda1e19aca7f67fb1

Changed Files

File Additions Deletions Status
public/harjoittelupaikat.php +34 -12 modified
src/hae_harjoittelupaikat.php +0 -20 deleted

Full Patch

diff --git a/public/harjoittelupaikat.php b/public/harjoittelupaikat.php
index b037a31..d04c826 100644
--- a/public/harjoittelupaikat.php
+++ b/public/harjoittelupaikat.php
@@ -1,3 +1,21 @@
+<?php
+    include "../src/connect.php";
+
+    $sql = "SELECT * FROM harjoittelupaikat";
+    $result = $conn->query($sql);
+
+    $harjoittelupaikat = [];
+    if ($result->num_rows>0) {
+        while($row = $result->fetch_assoc()) {
+            $harjoittelupaikat[] = $row;
+        }
+    } else {
+        echo "Harjoittelupaikkoja ei löytynyt";
+    }
+
+    $conn->close();
+?>
+
 <html lang="en">
 <head>
     <meta charset="UTF-8">
@@ -12,18 +30,22 @@
     </h1>
     <a href="../public/uusharjoittelupaikka.php">Lisää harjoittelupaikka</a>
     <main>
-        <section>
-            <div class="table-container">
-                <table>
-                    <tr>
-                        <th>Nimi</th>
-                        <th>Ohjaaja</th>
-                        <th>Yhteystiedot</th>
-                    </tr>
-                    <?php include "../src/hae_harjoittelupaikat.php"; ?>
-                </table> 
-            </div>
-        </section>
+        <table>
+            <tr>
+                 <th>Nimi</th>
+                 <th>Ohjaaja</th>
+                 <th>Yhteystiedot</th>
+             </tr>
+            <?php foreach ($harjoittelupaikat as $harjoittelupaikka): ?>
+                <tr>
+                    <?php 
+                        echo "<td>" . $harjoittelupaikka["nimi"] . "</td>";
+                        echo "<td>" . $harjoittelupaikka["ohjaaja"] . "</td>";
+                        echo "<td>" . $harjoittelupaikka["yhteystiedot"] . "</td>";
+                    ?>
+                </tr>
+            <?php endforeach; ?>
+        </table>
     </main>
 	<?php include "../src/footer.php"; ?>
 </body>
diff --git a/src/hae_harjoittelupaikat.php b/src/hae_harjoittelupaikat.php
deleted file mode 100644
index 06b335a..0000000
--- a/src/hae_harjoittelupaikat.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-include "../src/connect.php";
-
-$sql = "SELECT * FROM harjoittelupaikat";
-$result = $conn->query($sql);
-
-if ($result->num_rows>0) {
-	while($row = $result->fetch_assoc()) {
-		echo "<tr>";
-			echo "<td>" . $row["nimi"] . "</td>";
-			echo "<td>" . $row["ohjaaja"] . "</td>";
-			echo "<td>" . $row["yhteystiedot"] . "</td>";
-		echo "</tr>";
-	}
-} else {
-	echo "Harjoittelupaikkoja ei löytynyt";
-}
-
-$conn->close();
-?>