SHARE
TWEET

Untitled

a guest Sep 4th, 2018 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.   // Server Zugangsdaten festlegen
  4.   $servername = "localhost";
  5.   $username = "root";
  6.   $password = "";
  7.   $dbname = "datenbankname";
  8.  
  9.   // Verbindung herstellen
  10.   $conn = mysqli_connect($servername, $username, $password, $dbname);
  11.  
  12.   // Verbindung pruefen
  13.   if (!$conn) {
  14.     die("Connection failed: " . mysqli_connect_error());
  15.   }
  16.  
  17. ?>
  18.  
  19. <!-- BLOCK SPACER -->
  20.  
  21. <table>
  22.   <tr>
  23.     <th>ID</th></th>First name</th><th>Last name</th>
  24.   </tr>
  25.  
  26.   <?php
  27.  
  28.   // Befehl festlegen
  29.   $sql = "SELECT id, firstname, lastname FROM Users";
  30.  
  31.   // Befehl ausfuehren
  32.   $result = mysqli_query($conn, $sql);
  33.  
  34.   // Antwort pruefen
  35.   if (mysqli_num_rows($result) > 0) {
  36.  
  37.     // Antwort reihenweise ausgeben
  38.     while($row = mysqli_fetch_assoc($result)) { ?>
  39.  
  40.       <tr>
  41.         <td><?php echo $row['id']; ?></td><td><?php echo $row['firstname']; ?></td><td><?php echo $row['lastname']; ?></td>
  42.       </tr>
  43.  
  44.     <?php }
  45.  
  46.   } else {
  47.     echo "0 results";
  48.   }
  49.  
  50.   ?>
  51.  
  52. </table>
  53.  
  54. <!-- BLOCK SPACER -->
  55.  
  56. <?php
  57.  
  58.   // Verbindung schliessen
  59.   mysqli_close($conn);
  60.  
  61. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top