0% found this document useful (0 votes)
21 views2 pages

PHP Code

The document is an HTML file that displays an employee list from a MySQL database. It connects to the database, retrieves employee details such as ID, name, department, telephone, salary, and score, and presents them in a table format. If no records are found, it outputs a message indicating that no records are available.

Uploaded by

ahlamabdikhadar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

PHP Code

The document is an HTML file that displays an employee list from a MySQL database. It connects to the database, retrieves employee details such as ID, name, department, telephone, salary, and score, and presents them in a table format. If no records are found, it outputs a message indicating that no records are available.

Uploaded by

ahlamabdikhadar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

<!

DOCTYPE html>
<html>
<head>
<title>Employee List</title>
</head>
<body>

<h2>Employee Details</h2>

<?php
// Database connection
$conn = new mysqli("localhost", "root", "", "mydata");

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// SQL query
$sql = "SELECT id, name, depart, tell, salary, score FROM emp";
$result = $conn->query($sql);

// Check if data exists


if ($result->num_rows > 0) {

echo "<table border='1'>";


echo "<tr>
<th>ID</th>
<th>Name</th>
<th>Department</th>
<th>Telephone</th>
<th>Salary</th>
<th>Score</th>
</tr>";

// Fetch and display rows


while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>".$row['id']."</td>
<td>".$row['name']."</td>
<td>".$row['depart']."</td>
<td>".$row['tell']."</td>
<td>".$row['salary']."</td>
<td>".$row['score']."</td>
</tr>";
}

echo "</table>";

} else {
echo "No records found.";
}

// Close connection
$conn->close();
?>

</body>
</html>

You might also like