Advertisement
Guest User

posts.php

a guest
Mar 9th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 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 = "elad";
  15. $password = "12345";
  16. $dbname = "forum";
  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 username,title,id FROM posts";
  26. $result = $conn->query($sql);
  27.  
  28. echo "RECENT POSTS:";
  29.  
  30. if ($result->num_rows > 0) {
  31.     echo "<table><tr><th>Auther</th><th>Title</th></tr>";
  32.     // output data of each row
  33.     while($row = $result->fetch_assoc()) {
  34.         echo "<tr><td>" . $row["username"]. "</td><td>" . $row["title"]. " </td></tr>";
  35.         echo "<tr><td>" ."<a href=\"posts2.php?del=".$row['id']."\">read more...</a><br />". " </td></tr>";
  36.     }
  37.     echo "</table>";
  38. } else {
  39.     echo "<br><br>";
  40.     echo "There are no posts";
  41. }
  42.  
  43. $conn->close();
  44. ?>
  45.  
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement