Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Server Zugangsdaten festlegen
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "datenbankname";
- // Verbindung herstellen
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Verbindung pruefen
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- ?>
- <!-- BLOCK SPACER -->
- <table>
- <tr>
- <th>ID</th></th>First name</th><th>Last name</th>
- </tr>
- <?php
- // Befehl festlegen
- $sql = "SELECT id, firstname, lastname FROM Users";
- // Befehl ausfuehren
- $result = mysqli_query($conn, $sql);
- // Antwort pruefen
- if (mysqli_num_rows($result) > 0) {
- // Antwort reihenweise ausgeben
- while($row = mysqli_fetch_assoc($result)) { ?>
- <tr>
- <td><?php echo $row['id']; ?></td><td><?php echo $row['firstname']; ?></td><td><?php echo $row['lastname']; ?></td>
- </tr>
- <?php }
- } else {
- echo "0 results";
- }
- ?>
- </table>
- <!-- BLOCK SPACER -->
- <?php
- // Verbindung schliessen
- mysqli_close($conn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement