我怎样才能给每个职位的特殊链接在PHP? [英] How can I give a special link to every post in php?
问题描述
正如你所看到的,我正在使用echo进行'发布'。我正在回显数据库表中的数据。我需要一个特殊的链接,只会导致特定的帖子,就像每个帖子都应该有一个特定的链接。我怎样才能使用PHP和/或如果我不能使用PHP的,我怎么能在JavaScript中做到这一点?你可以看到下面的代码。
$ sql =SELECT Nick,Mail,Message,ID FROM Approved;
$ result = mysqli_query($ conn,$ sql);
$ b $ if(mysqli_num_rows($ result)> 0){
//每行输出数据
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>'。 尼克:。尼克。 < / DIV>;
echo'< div style =`在此输入代码text-align:center; font-size:100%; margin-top:4%; font-family:Arial,Helvetica,sans -serif>'。消息:。 $消息。 < / DIV>;
}
} else {
echo0 results;
这:
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]。''。 尼克:。尼克。 < / A>< / DIV>;
这样您就可以在URL中传递特定结果的ID。在该页面中,您可以使用 $ _ GET ['id']
。
获取ID。您可以轻松查询并显示特定记录的结果。
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";
}
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.
这篇关于我怎样才能给每个职位的特殊链接在PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!