<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Read from an SQL table</title>
</head>
<body style="font-family:Arial">
<table cellpadding="2" cellspacing="2" border="1" width="90%" align="center" style="border-collapse: collapse;">
<?php
// 1: Open database
$username = "root";
$password = "";
$host="localhost";
$database= "myproject";
// 2 connect to the database
$conn = new mysqli($host,$username,$password,$database);
?>
<p align="center" style="font-size:xx-large">User Details</p>
<?php
// 3. Table and table header
echo "<table cellpadding=\"2\" cellspacing=\"2\" border=\"1\" width=\"90%\" ".
"align=\"center\" style=\"border-collapse: collapse;\">";
echo "<tr>"; // Display the fields names in the header
echo "<td style=\"text-align: center\"><b>Login</b></td>";
echo "<td style=\"text-align: center\"><b>Type</b></td>";
echo "<td style=\"text-align: center\"><b>Last Used</b></td>";
echo "</tr>";
// 4 Query the table user
$query = "select * from user";
$result = $conn->query($query);
if ($result->num_rows > 0) {
// 5 Read row and display the fields
while($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>".$row['login']."</td>";
echo "<td>".$row['type']."</td>";
echo "<td>".$row['last_used']."</td>";
echo "</tr>";
}
// Clear select memory
$result->free();
}
// 6 Close connection
$conn->close();
?>
</table>
</body>
</html>