php - How to display content in random order? -
with code below displaying questions retrieved database:
$qandaquery = "select q.questionid, q.questionno, q.questioncontent question q sessionid = ? grouping q.questionid order q.questionid"; $qandaqrystmt=$mysqli->prepare($qandaquery); // need phone call bind_param 1 time $qandaqrystmt->bind_param("i",$session); // result , assign variables (prefix 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 $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 says question
:
<p><strong>question # <?php echo $q; ?> :</strong></p> <?php $q++; ?>
i want remain same place
but displays question details:
<p><?php echo htmlspecialchars($arrquestionno[$key]) . ": " . htmlspecialchars($arrquestioncontent[$key]); ?></p>
i want display questions in random order. illustration if have 3 questions below:
question 1: 1. 2+2? question 2: 2. 3+3? question 3: 3. 4+4?
it displayed in order example:
question 1: 2. 3+3? question 2: 3. 4+4? question 3: 1. 2+2?
instead of order q.questionid
utilize order rand()
php mysqli
No comments:
Post a Comment