Advertisement
lemansky

Untitled

Mar 2nd, 2022
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.21 KB | None | 0 0
  1. <?php
  2.     $servername = "localhost";
  3.     $username = "root";
  4.     $password = "";
  5.     $dbname = "myDB";
  6.  
  7.     // Create connection
  8.     $conn = new mysqli($servername, $username, $password, $dbname);
  9.     // Check connection
  10.     if ($conn->connect_error) {
  11.       die("Connection failed: " . $conn->connect_error);
  12.     }
  13.  
  14.     $sql = "SELECT id, firstname, lastname FROM MyGuests";
  15.     $result = $conn->query($sql);
  16.  
  17.     // if ($result->num_rows > 0) {
  18.     //   // output data of each row
  19.     //   while($row = $result->fetch_assoc()) {
  20.     //     echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
  21.     //   }
  22.     // } else {
  23.     //   echo "0 results";
  24.     // }
  25.     // $conn->close();
  26.  
  27. ?>
  28. <!DOCTYPE html>
  29. <html lang="en">
  30. <head>
  31.     <meta charset="UTF-8">
  32.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  33.     <title>Document</title>
  34. </head>
  35. <body>
  36.     <ul>
  37.         <li>
  38.             <?php
  39.             if ($result->num_rows > 0) {
  40.                   // output data of each row
  41.               while($row = $result->fetch_assoc()) {
  42.                 echo "id: " . $row["id"]. " - Name: <a href='#'>" . $row["firstname"]. "</a> " . $row["lastname"]. "<br>";
  43.               }
  44.             } else {
  45.               echo "0 results";
  46.             }
  47.             $conn->close();
  48.             ?>
  49.         </li>
  50.     </ul>
  51. </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement