I have this php code:
for($i=0;$i<3;$i++) {
echo 'Question'.$i.'</br>';
echo 'Answer..</br>';
echo '<form action="" method="POST">';
echo '<textarea name="answer"></textarea>';
echo '</br><button name="answer_button'.$i.'"><b>Answer</b></button>';
echo '</form>';
}
Now I want to get the question number for which the answer_button
is clicked.
Closest I could get was this:
for($i=0;$i<3;$i++) {
echo 'Question'.$i.'</br>';
echo 'Answer..</br>';
echo '<form action="" method="POST">';
echo '<textarea name="answer"></textarea>';
echo '</br><button name="answer_button"><b>Answer</b></button>';
echo '</form>';
if(isset($_POST['answer_button'])) {
echo $i;
break;
}
}
This gives me Question number but it will not print other questions in loop once the button is clicked.
Is there no solution without using javaScript?