With code below I am displaying questions retrieved from database:
$qandaquery = "SELECT q.QuestionId, q.QuestionNo, q.QuestionContent
FROM Question q
WHERE SessionId = ?
GROUP BY q.QuestionId
ORDER BY q.QuestionId";
$qandaqrystmt=$mysqli->prepare($qandaquery);
// You only need to call bind_param once
$qandaqrystmt->bind_param("i",$session);
// get result and assign variables (prefix with db)
$qandaqrystmt->execute();
$qandaqrystmt->bind_result($qandaQuestionId,$qandaQuestionNo,$qandaQuestionContent);
$arrQuestionId = array();
$arrQuestionNo = array();
$arrQuestionContent = array();
while ($qandaqrystmt->fetch()) {
$arrQuestionId[ $qandaQuestionId ] = $qandaQuestionId;
$arrQuestionNo[ $qandaQuestionId ] = $qandaQuestionNo;
$arrQuestionContent[ $qandaQuestionId ] = $qandaQuestionContent;
}
$qandaqrystmt->close();
foreach ($arrQuestionId as $key=>$question) {
?>
<div class='lt-container'>
<p><strong>QUESTION <span id="quesnum"></span>:</strong></p>
<p><?php echo htmlspecialchars($arrQuestionNo[$key]) . ": " . htmlspecialchars($arrQuestionContent[$key]); ?></p>
</div>
<?php
}
?>
Now WHERE it says QUESTION:
<p><strong>QUESTION # <?php echo $q; ?> :</strong></p>
<?php
$q++;
?>
I want that to stay the same place
But where it displays the question details:
<p><?php echo htmlspecialchars($arrQuestionNo[$key]) . ": " . htmlspecialchars($arrQuestionContent[$key]); ?></p>
I want it to display the questions in RANDOM order. So for example if I have 3 questions as below:
QUESTION 1:
1. What is 2+2?
QUESTION 2:
2. What is 3+3?
QUESTION 3:
3. What is 4+4?
It could be displayed in this order as an example:
QUESTION 1:
2. What is 3+3?
QUESTION 2:
3. What is 4+4?
QUESTION 3:
1. What is 2+2?
Instead of
ORDER BY q.QuestionIduseORDER BY RAND()