Stop mysql value from duplicate in php oop? -


i'm generating questions mysql loop. question_category not duplicate on every row, displayed once on top of first question in category?

right now:
question category 1 question1 (o) (o) (o)
question category 1 question2 (o) (o) (o)
question category 2 question1 (o) (o) (o)
question category 2 question2 (o) (o) (o)

my goal:
question category 1
question1 (o) (o) (o)
question2 (o) (o) (o)
question category2
question1 (o) (o) (o)
question2 (o) (o) (o)

<?php // generate active questions db $query = "select * questions active=1 , question_sort=1 order sort_by"; $result = @mysqli_query($con, $query); ?> <div class="questions-1">       <table width="auto" border="0">         <tr>             <td></td>             <td></td>             <td class="answer_value">0</td>             <td class="answer_value">1fta</td>             <td class="answer_value">2</td>           </tr> <?php if ($result) { while($row = mysqli_fetch_array($result, mysqli_assoc)) {     // question body each question     $body = $row['question_body'];     // question id each question     $question_id = $row['question_id'];     // question category each question     $question_category = $row['question_category'];           echo '<tr>             <td class="question">'.$question_category.'</td>             <td class="question">'.$body.'</td>             <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="0" ></td>             <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="1" ></td>             <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="2" ></td>           </tr>'; } ?> </table></div> 

since query apparently returns things ordered questions of specific category grouped together....

<?php $currcategory = ""; // holder keep track of current category working with. if ($result) { while($row = mysqli_fetch_array($result, mysqli_assoc)) {     // question body each question     $body = $row['question_body'];     // question id each question     $question_id = $row['question_id'];     // question category each question     $question_category = $row['question_category'];     if ($currcategory !== $question_category) { // category has changed lets create 'header' row.         $currcatgory = $question_category;         echo '<tr><td colspan="5">'.$currcategory.'</td></tr>';     }           echo '<tr>             <td class="question">'.$question_category.'</td>             <td class="question">'.$body.'</td>             <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="0" ></td>             <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="1" ></td>             <td class="answer"><input type="radio" name="answer_value['.$question_id.']" value="2" ></td>           </tr>'; } ?> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -