Reputation: 45
This is a FAQ page. I am currently having problem to show the answer with its respective question. The page is able to show all the questions in the database as I have already placed them in the loop. However ,when I clicked on any questions to view the answer. It will only collapse the first question and the show answer that appears first in my database. I want it to collapse and show the answer with respective to its question when I clicked on the different questions. How should I go about doing it?
Below is my code:
<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>";
}
?>
Upvotes: 2
Views: 52
Reputation: 307
MOdify your Query and pass and id either from the URL using GET or using jQuery via POST and filter the results for that ID only.
$result = mysql_query("SELECT * FROM faq where status='Enabled' AND id = {My ID here} ORDER BY id ASC;");
Upvotes: 1