我有来自mysql的每个帖子/记录的ID,我不知道如何为他们建立一个特殊的链接。我问了类似的问题,他们告诉我使用$ _GET,但我真的不知道如何,如果你可以输入代码或者告诉我怎么样会有所帮助。我怎么能在创建链接时回复特定的帖子具体的链接?这是代码。
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$Nick = $row["Nick"];
$Mail = $row["Mail"];
$Message = $row["Message"];
$ID = $row["IDNumber"];
echo '<div style ="text-align:center; font-size: 100%; margin-top: 9%; font-family:Arial, Helvetica, sans-serif">' . "Nick: " . $Nick . '</div>';
echo '<div style ="text-align:center; font-size: 100%; margin-top: 9%; font-family:Arial, Helvetica, sans-serif"><a href="?id=' . $id .'"' . "Message: " . $Message . '</a></div>';
}
} else {
echo "0 results";
}
?>
答案 0 :(得分:1)
你可以这样做:
<?php
if(isset($_GET['id'])) {
// id index exists
$id = $_GET['id'];
$sql = "SELECT * FROM tablename WHERE id = " . $id;
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) == 0) {
echo "post does not exist";
}
else {
//display data like you did
}
}
else {
//your old code
}
网址将类似于yourpagename.php?id = 1