我无法使用数据库中的ID选择一组特定数据。例如,员工有一个唯一的ID为e000000001,当我点击索引中的查看按钮将导致员工详细信息页面显示该特定员工的详细信息,而不是所有员工的详细信息。谢谢。按ID选择数据PHP
//从index.php页面
<?php
require_once 'db/dbEmpList.php';
$sqlStr = "SELECT * FROM employees;";
$result = $connection->query($sqlStr);
if ($result->num_rows > 0) {
echo "<table class='table table-sm'><thread><tr><th>Full Name</th><th>Employee ID</th><th>Position</th><th>View Employee's Details</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>"
. $row["empName"]. "</td><td>"
. $row["empID"]. "</td><td>"
. $row["position"]. "</td>"
. "<td> <a href='employeedetail.php?id={$row["empID"]}'>View</a>"
. "</td></tr>";
}
}
从//员工页面
require_once 'db/dbEmpDetail.php';
$sql = "SELECT * FROM employees where empID = '{$row["empID"]}' ";
$result = mysqli_query($connection, $sql);
if (mysqli_num_rows($result)) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>' .'<td>' .$row["empName"].'</td>'.'<td>'. $row["position"].'</td>' .'<td>'.$row["empNRIC"].'</td>' .'<td>'.$row["empID"].'</td>' .'<td>'.$row["empEmail"].'</td>' .'<td>'.$row["empPwd"].'</td>' . "</tr>";
}
} else {
echo "0 results";
}
mysqli_close($connection);
?>
看起来你需要写'employeedetail.php'。这不是我们可以为您解答的问题。 – tadman
你忘了描述这个问题。 “我有麻烦”并没有真正告诉我们什么是错的。 – David
谢谢你的回复。我从数据库中检索的数据是全部员工。我不知道如何通过Id检索特定的一组数据。 – wen