Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Give this a try.......</p> <pre><code>$question = array(); while ($selectedstudentanswerstmt-&gt;fetch()) { // assuming you don't need the StudentId $questions[] = array('no' =&gt; $detailsQuestionNo, 'content' =&gt; $detailsQuestionContent); } </code></pre> <p>and</p> <pre><code>foreach ($questions as $key =&gt; $question) { echo '&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; ' . htmlspecialchars($question['no']) . ': ' . htmlspecialchars($question['content']) . '&lt;/p&gt;' . PHP_EOL; } </code></pre> <h1>EDITED</h1> <p>Or you can try this if your grouping by question:</p> <pre><code>$question = array(); while ($selectedstudentanswerstmt-&gt;fetch()) { if (true === isset($questions[$detailsQuestionId])) { $questions[$detailsQuestionId]['students'][] = $detailsStudentId; } else { $questions[$detailsQuestionId] = array(); $questions[$detailsQuestionId]['no'] = $arrQuestionNo; $questions[$detailsQuestionId]['content'] = $arrQuestionContent; $questions[$detailsQuestionId]['students'] = array(); $questions[$detailsQuestionId]['students'][] = $detailsStudentId; } } foreach ($questions as $questionId =&gt; $question) { // $question['no'] // $question['content'] foreach($question['students'] AS $key =&gt; $studentId) { // $studentId } } </code></pre> <h1>Or if your grouping by userID...</h1> <pre><code>$students = array(); while ($selectedstudentanswerstmt-&gt;fetch()) { if (false === isset($students[$detailsStudentId])) { $students[$detailsStudentId] = array(); } $students[$detailsStudentId][$detailsQuestionId] = array('no' =&gt; $arrQuestionNo, 'content' =&gt; $arrQuestionContent; } foreach ($students AS $studentId =&gt; $questions) { // $studentId foreach ($questions AS $questionId =&gt; $question) { // $questionId // $question['no'] // $question['content'] } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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