Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to show all the rows in my faq page from my faq table?
    text
    copied!<p>This is a FAQ page. The page is only able show the last row of question with respect to its answer in the database. I want it to collapse and show the answer with respect to its question when I clicked all questions I have in the database. How should I go about doing it? Thanks! Appreciated lots! panel. I want it to be shown as:</p> <p>Question A</p> <ul> <li>Answer A</li> </ul> <p>Question B</p> <ul> <li>Answer B</li> </ul> <p>Question C</p> <ul> <li>Answer C</li> </ul> <p>Now it is showing only this:</p> <p>Question C</p> <ul> <li>Answer C</li> </ul> <p>Table Structure:</p> <p><strong># Name Type Collation Null Default</strong><br> 1 Id Int No None<br> 2 Question Varchar Latin1_swedish_ci No None<br> 3 Answer Varchar Latin1_swedish_ci No None<br> 4 Status Varchar Latin1_swedish_ci No None<br> 5 Date_added Date No None </p> <p>Below is my code:</p> <pre><code> &lt;h1&gt;FAQ&lt;/h1&gt; &lt;?php $result = mysql_query("SELECT * FROM faq ORDER BY id ASC;"); if($result &gt;= 1 ){ $i=1; while ($row = mysql_fetch_array($result)) { $id = $row["id"]; ?&gt; &lt;?php $i++; } } ?&gt; &lt;?php $queryquestion = mysql_query("SELECT question FROM faq where status='Enabled' AND id='$id' ORDER BY id ASC;")or die(mysql_error()); $data = mysql_fetch_assoc($queryquestion); $question = $data['question']; $rows = mysql_num_rows($queryquestion); if($rows != 0){ echo ' &lt;hr class="colorgraph"&gt; &lt;div class="panel-group" id="accordion"&gt; '; $i = 0; $j = 0; while($i &lt; $rows) { $queryanswer = mysql_query("SELECT answer FROM faq WHERE id='$id' AND question='$question'") or die(mysql_error()); $data = mysql_fetch_assoc($queryanswer); $answer = $data['answer']; echo ' &lt;div class="panel panel-default"&gt; &lt;div class="panel-heading"&gt; &lt;h4 class="panel-title"&gt;&lt;a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse'.$i.'"&gt; '.$question.'&lt;/h4&gt; &lt;/a&gt;&lt;/div&gt; &lt;div id="collapse'.$i.'" class="panel-collapse collapse"&gt; &lt;div class="panel-body"&gt;'.$answer.'&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; '; $i++; } echo' &lt;/div&gt; '; }else{ echo "No Questions Found"; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload