你需要在你的文件中添加条件与该表(我假设它是profile.php文件)。
如果你的代码看起来是这样的:
$mysqli = new mysqli("localhost", "user", "password", "database");
$result = $mysqli->query("SELECT * FROM users");
while ($row = $result->fetch_assoc()) {
echo "<table>";
echo "<tr>";
...
echo "<td><a href='profile.php?id=" . $row['id'] . "'>Details</a></td>";
...
echo "</tr>";
echo "</table>";
}
只要改变这样说:
$mysqli = new mysqli("localhost", "user", "password", "database");
if (!empty($_GET['id'])) {
$id = $mysqli->real_escape_string($_GET['id']);
$result = $mysqli->query("SELECT * FROM users WHERE id=".$id);
$row = $result->fetch_assoc();
echo "User data: <br>";
echo "Name: ".$row['name']."<br>";
...
} else {
$result = $mysqli->query("SELECT * FROM users");
while ($row = $result->fetch_assoc()) {
echo "<table>";
echo "<tr>";
...
echo "<td><a href='profile.php?id=" . $row['id'] . "'>Details</a></td>";
...
echo "</tr>";
echo "</table>";
}
}
我把它像你说..但是,当我点击“详细信息”无法显示什么都没有......只需在URL栏中显示ID号。 – user353232
@ user353232 - 它应该工作。你把你的profile.php文件? – shaggy