Advertisement
Guest User

Untitled

a guest
Mar 8th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. table, th, td {
  6. border: 1px solid black;
  7. }
  8. </style>
  9. </head>
  10. <body>
  11.  
  12. <?php
  13. $servername = "localhost";
  14. $username = "username";
  15. $password = "password";
  16. $dbname = "myDB";
  17.  
  18. // Create connection
  19. $conn = new mysqli($servername, $username, $password, $dbname);
  20. // Check connection
  21. if ($conn->connect_error) {
  22. die("Connection failed: " . $conn->connect_error);
  23. }
  24.  
  25. $sql = "SELECT id, firstname, lastname FROM MyGuests";
  26. $result = $conn->query($sql);
  27.  
  28. if ($result->num_rows > 0) {
  29. echo "<table><tr><th>ID</th><th>Name</th></tr>";
  30. // output data of each row
  31. while($row = $result->fetch_assoc()) {
  32. echo "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]. "</td></tr>";
  33. }
  34. echo "</table>";
  35. } else {
  36. echo "0 results";
  37. }
  38.  
  39. $conn->close();
  40. ?>
  41.  
  42. </body>
  43. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement