I have a few questions and answers stored in the same table. Column Q and A.
----ID----Q----A----
1 | Q1 | A1 |
2 | Q2 | A2 |
3 | Q3 | A3 |
I want to echo all questions into a div slider and all answers into another div slider.
Something like this:
<div>
<ul>
<li>Question 1</li>
<li>Question 2</li>
<li>Question 3</li>
</ul>
</div>
<div>
<ul>
<li>Answer 1</li>
<li>Answer 2</li>
<li>Answer 3</li>
</ul>
</div>
Im selecting all rows order by RAND, otherwise I would just run the selection again (n00b style). How do I perform this loop, starting with first column continue with next in correct order? My knowledge in PHP is quite limited.
Code (how Im used to print tables):
<ul id="fade">
<?php
$num = "100";
$questions = "SELECT * FROM quiz ORDER BY RAND() LIMIT $num";
$result = mysql_query($questions, $dbconnection);
for ($i=0; $i < mysql_num_fields($result); $i++) {
$rank = 1;
}
while($myRow = mysql_fetch_array($result)){
echo "<li>" .$myRow['q']. "</li>";
echo "<li>" .$myRow['a']. "</li>";
rank++;
}
?>
</div>
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.