问题
as you can see I'm making a 'post' using echo. I'm "echoing" the data from the database table. I need a special link that will lead to only specific post, like every post should have a specific link. How can I make that using php and/or if I cant use php for that how can I do it in javascript? You can see the code bellow.
$sql = "SELECT Nick, Mail, Message, ID FROM Approved";
$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"];
echo '<div style ="text-align:center; font-size: 100%; margin-top: 9%; font-family:Arial, Helvetica, sans-serif">' . "Nick: " . $Nick . '</div>';
echo '<div style =`enter code here`"text-align:center; font-size: 100%; margin-top: 4%; font-family:Arial, Helvetica, sans-serif">' ."Message:" . $Message . '</div>';
}
} else {
echo "0 results";
}
回答1:
Change your echo to something like this:
echo '<div style ="text-align:center; font-size: 100%; margin-top: 9%; font-family:Arial, Helvetica, sans-serif"><a href="url.php?id='.$row["ID"].'"' . "Nick: " . $Nick . '</a></div>';
So that you pass the ID of the particular result in the URL. And in that page you can get the ID using $_GET['id'].
Having the ID, you can easily query and display results for the particular record.
来源:https://stackoverflow.com/questions/31662730/how-can-i-give-a-special-link-to-every-post-in-php