简体   繁体   English

我怎样才能单独在MySQL数据库的表中选择一行在php的anthor页面中?

[英]how can i select one row from table in MySQL database alone in anthor page with php?

i create questions and answers system with php and i created page have all questions that recorded in table named questions and make beside every question reply link which directed to answer page, so i need to select this question that i want to comment on it from table and show it single in the answer page to make comments on it , how can i make this with php? 我用php创建问答系统,并且我创建的页面将所有问题记录在名为问题的表中,并在指向问题页面的每个问题答复链接旁边做,所以我需要从表中选择要对其进行评论的问题并在答案页面上显示它以发表评论,我该如何使用php?

this is my questions page code 这是我的问题页面代码

<?php  session_start();  $connection = new mysqli('localhost','root','','questionssystem') or die ("Database connection failed"); /*start questions*/$sql = "SELECT question_text FROM question"; $result = $connection->query($sql); echo'<h2>Questions page</h2>'; if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    echo '<form action="answers.php" method="post">';
    echo '<div class ="container">';
    echo "<p>question: " . $row["question_text"];
    echo '<span class="psw">If You want to reply this Question , please <a href="http://localhost:8080/questionssystem/answers.php" target="_self">Reply</a></span>';
    echo '</div>';
    echo '</form>'; } }else { echo "0 results";} /*end questions*/ $connection->close(); ?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="css_file.css">
</head>
<body></body></html>

Using Foreign Key - One column which links two different SQL tables! 使用外键-链接两个不同SQL表的一列!

https://www.w3schools.com/sql/sql_foreignkey.asp https://www.w3schools.com/sql/sql_foreignkey.asp

After reading you question i guess you want to provide a link "Reply" on question , so on redirect user can answer to that question, 阅读完您的问题后,我想您想在问题上提供“答复”链接,以便重定向用户可以回答该问题,

you can do is send question ID from database in GET to other page 您可以做的是将问题ID从GET中的数据库发送到其他页面

<a href="http://localhost:8080/questionssystem/answers.php?questionID=12" target="_self">Reply</a>

on answer page 在答案页面上

$QID = $_GET['questionID'];

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM