Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 87c6d130 authored by 65160027's avatar 65160027
Browse files

Add index.php

parent 07c58583
No related branches found
No related tags found
No related merge requests found
<?php echo "Natnicha Wettamma";
<?php
$servername = "db";
$username = "demo";
$password = "12456";
$dbname = "demo";
// Create connection
$conn = new mysqli($servername, $username, $password);
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "SELECT id, fname, lname FROM student";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<style>
table {
width: 60%;
margin: 20px auto;
border-collapse: collapse;
font-family: Arial, sans-serif;
text-align: left;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
}
th, td {
padding: 10px;
border: 1px solid #ddd;
}
th {
background-color: #4CAF50;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
</style>";
echo "<table>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
</tr>";
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . htmlspecialchars($row["id"]) . "</td>
<td>" . htmlspecialchars($row["fname"]) . "</td>
<td>" . htmlspecialchars($row["lname"]) . "</td>
</tr>";
}
echo "</table>";
} else {
echo "<p style='text-align:center; font-family:Arial; color:red;'>No results found</p>";
}
$conn->close();
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment