Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title> </title>
- </head>
- <style type="text/css">
- table, tr, td, th {
- border:1px solid black;
- }
- </style>
- <body>
- <?php
- $servername = "localhost";
- $username = "joostottens";
- $password = "";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=Cijferlijst", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo "";
- }
- catch(PDOException $e)
- {
- echo "Connection failed: " . $e->getMessage();
- }
- ?>
- <form method="POST">
- <select name='voornaam'>
- <option value="">Alle leerlingen</option>
- <?php
- $sql = "select distinct voornaam from Leerling order by voornaam";
- $result = $conn->query($sql);
- foreach ($result as $row) {
- echo "<option value='". $row["voornaam"]. "' >". $row["voornaam"]. "</option>";
- }
- ?>
- </select>
- <input type='submit' name="toon" value="toon">
- </form>
- <table>
- <th>id</th><th>voornaam</th><th>achternaam</th><th>emailadres</th><th>klas</th><th>id</th><th>vak</th><th>leerling id</th><th>cijfer</th>
- <?php
- if (isset($_POST['toon']) and $_POST["voornaam"] != "") {
- $sql = "select * from Leerling INNER JOIN Cijfer2 ON Leerling.id = Cijfer2.Leerling_id where voornaam = '". $_POST["voornaam"]. "'";
- }
- else {
- $sql="SELECT * FROM Leerling INNER JOIN Cijfer2 ON Leerling.id = Cijfer2.leerling_id";
- }
- $result = $conn->query($sql);
- foreach ($result as $row){
- echo "<tr>";
- echo "<td>" . $row["leerling_id"]. "</td>";
- echo "<td>" . $row["voornaam"]. "</td>";
- echo "<td>" . $row["achternaam"]. "</td>";
- echo "<td>" . $row["emailadres"]. "</td>";
- echo "<td>" . $row["klas"]. "</td>";
- echo "<td>" . $row["id"]. "</td>";
- echo "<td>" . $row["vak"]. "</td>";
- echo "<td>" . $row["leerling_id"]. "</td>";
- echo "<td>" . $row["cijfer"]. "</td>";
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement