for($j = 0; $j < $length; $j++){
while($answersRow = mysql_fetch_row($fetch)){
if($answersRow[0] == $curr_answer_id[$j]){
echo "<input type='checkbox' value='$answersRow[0]' checked>$answersRow[1]</input> ";
} else {
echo "<input type='checkbox' value='$answersRow[0]'>$answersRow[1]</input> ";
}
}
}
Assuming $fetch is my result, here’s my dilemma. The for loop represents the array of checkboxes. The first loop around, everything works fine. However, any more than that, we no longer cycle through the while loop because of the internal mysql pointer. I know I can move the pointer around using mysql_data_seek(), but don’t have an idea on how to do so usefully. If I move it back to 0, then it just outputs everything for as many things that were checked.
I basically want to traverse through for each question through the database but without any overlap. It is a bit hard to explain so I apologize if I am not explaining this simple problem properly; I’ll try and clarify if need be.
You can save the results of your first while in an array:
Also sorry If I misunderstood your question but It is not so clear what you are asking for
Addendum
After reading better your question if I understood correctly you want to achive everything within only one loop. In this case you can save the html you need in the first while like this:
At this point with one loop you have built the html you need and they are in
$firstLoopand$secondLoop. This is of course faster then any other solutions