On a previous page I have allowed the user to choose how many questions and how many choices for each question they want.
PAGE 1
- Code: Select all
echo "<h1>Change the values in each box</h1>\n";//title
echo "<form method=\"post\" action=\"addToDb.php\">\n";//start form
for($q = 1; $q <= $questions; $q++){//loop through number of questions required
echo " <input name='questions[]' type='text' value='question $q' /><br/>\n";
for($opt = 1; $opt <= $choices; $opt++){//loop through number of options required
echo " <input name='choice[]' type='text' value='option $opt' /><br/>\n";
}
}
echo " <input name='submit' type='submit' value='SUBMIT' />\n";//submit form
echo "</form>";//close form
Page 2
- Code: Select all
$q = $_POST['questions'];
$c = $_POST['choice'];
foreach($q AS $v){
echo $v . "<br/>\n";
foreach($c AS $value){
echo " " . $value . "<br/>\n";
}
}
My problem is that the second for loop on page two seems to run through all the choices before moving on to question 2
EXAMPLE - what I want
Q1
C1
C2
C3
C4
Q2
C1
C2
C3
C4
Q3
C1
C2
C3
C4
EXAMPLE - what I GET
Q1
C1
C2
C3
C4
C1
C2
C3
C4
C1
C2
C3
C4
Q2
C1
C2
C3
C4
C1
C2
C3
C4
C1
C2
C3
C4
Q3
C1
C2
C3
C4
C1
C2
C3
C4
C1
C2
C3
C4


