Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

javascript - How can I give a special link to every post in php?

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";
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...