Advertisement
Boyan5

MySQL and PHP

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