按ID PHP选择数据

时间:2017-07-06 16:19:58

标签: php mysql database

我无法使用数据库中的ID选择一组特定数据。例如,员工1的唯一ID为e000000001,当我单击索引中的查看按钮时,将显示员工详细信息页面,其中显示该特定员工的详细信息,而不是所有员工的详细信息。详情。谢谢。

//来自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); 
?>

1 个答案:

答案 0 :(得分:0)

// FROM EMPLOYEE PAGE

检索URL查询字符串的方式是错误的。您应该使用$ _GET从URL获取查询字符串。在你的情况下它应该是$ _GET [&#39; id&#39;]。请参阅以下代码:

style.display