<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// SQL query
$sql = "SELECT id, name, email FROM users";
// Execute query and get result object
$result = $conn->query($sql);
// Check if any rows are returned
if ($result->num_rows > 0) {
// Start table markup
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Email</th></tr>";
// Loop through each row and output data in table cells
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["email"]."</td></tr>";
}
// End table markup
echo "</table>";
} else {
echo "0 results";
}
// Close connection
$conn->close();
?>