单击ID后,如何显示与其数据库中的ID对应的答案


How to show answer respective to its ID from database once the ID is clicked?

这是一个FAQ页面。我目前无法显示答案及其各自的问题。该页面能够显示数据库中的所有问题,因为我已经将它们放在循环中。但是,当我单击任何问题以查看答案时。它只会折叠第一个问题和显示我的数据库中首先出现的答案。我希望它折叠并在我单击不同问题时显示与其问题相关的答案。我应该怎么做?

下面是我的代码:

<h1>FAQ</h1>    <?php
  $result = mysql_query("SELECT * FROM faq where status='Enabled' ORDER BY id ASC;");
     if($result >= 1 ){             
        echo '<hr class="colorgraph">';   
        $i=1;

  while ($row = mysql_fetch_assoc($result))
        {  $id = $row["id"];  
?>
    <div class="panel-group" id="accordion"> //this is dropdown box.
         <div class="panel panel-default">
    <div class="panel-heading">
    <h4 class="panel-title"><a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                <?= $row['question'] ?></h4>
        </a></div> // the user has to click this to dropdown to see the information below
       <div id="collapseOne" class="panel-collapse collapse">
      <div class="panel-body"><?= $row['answer'] ?></div> // this is the information that will be shown once it dropped down
         </div>
        </div>   

     <?php
      $i++;  }
    }else{
        echo "No Questions Found<br></table>";
    }
                              ?>

使用 GET 或通过 POST 使用 jQuery 从 URL 传递和 ID,并仅过滤该 ID 的结果。

$result = mysql_query("SELECT * FROM faq where status='Enabled' AND id = {My ID here} ORDER BY id ASC;");