Advertisement
Guest User

zadanko_filmiki

a guest
Oct 17th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7.     <title>W S T A W</title>
  8.     <style>
  9.         table {
  10.         border-collapse: collapse;
  11.         }
  12.  
  13.         table, th, td {
  14.         border: 1px solid black;
  15.         }
  16.         th{
  17.             background-color: #ccc;
  18.         }
  19.         tr:hover{
  20.             background-color: #ddd;
  21.             cursor: pointer;
  22.         }
  23.     </style>
  24. </head>
  25. <body style="font-family: Arial;">
  26.  
  27. <?php
  28. $dsn = "mysql:host=localhost;dbname=dane";
  29. $user = "root";
  30. $pass = "";
  31. try{
  32.     $pdo = new PDO($dsn, $user, $pass);
  33.     $zapytanie = "SELECT tytul, rok, ocena FROM filmy";
  34.     $wynik = $pdo->query($zapytanie);
  35.     echo "<table cellpadding=3px><tr><th>Tytuł</th><th>Rok</th><th>Ocena</th></tr>";
  36.     foreach($wynik as $wiersz){
  37.         echo "<tr><td>$wiersz[0]</td><td>$wiersz[1]</td><td>$wiersz[2]</td></tr>";
  38.     }
  39.     echo "</table>";
  40.     $pdo = null;
  41. }
  42. catch (PDOException $e){
  43.     echo "<div style='color:red; border: 2px solid crimson; padding: 5px; width: 50%; margin: 10px;'><div style='font-weight: bolder; border-bottom: 2px solid crimson;'>Błąd połączenia!</div> $e</div>";
  44. }  
  45. ?>
  46.  
  47. </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement