RE: [PHP] generating arrays using $_REQUEST/$_GET/$_POST
| From: | Matt Matijevich | Date: | Thu, 22 Jan 2004 19:32:12 +0000 |
| Subject: | RE: [PHP] generating arrays using $_REQUEST/$_GET/$_POST | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-175458@lists.php.net to get a copy of this message | ||
<snip>
echo "<form method='get' action='exams2.php'>";
$Student = array ("albert Einstein", "Ivan the Terrible", "Napolon",
"Simon Bolivar", "Issac Newton");
while(list(,$name)=each($Student)){
echo "what grade did $name get in Maths?";
echo"<br><br>";
echo "<select name='Math[]'>
<option>Grade A</option>
<option>Grade B</option>
<option>Grade C</option>
<option>Grade D</option>
<option>Grade E</option>
</select>";
echo "<br><br>";
echo "<input type='hidden' name='Student[]'
value='$name'>";
}
echo "<input type='submit'></form>";
Here is the processing code:
$Math = $_REQUEST["Math"];
$Student[] = $_REQUEST["Student"];
while(list($index, $value)=each($Math)){
$gradeStudent[]=$Math[$index].$Student[$index];
}
Asort($gradeStudent);
while(list($index, $value) = each($gradeStudent)){
echo"<br>$Student[$index] - $Math[$index]";
}
</snip>
Hmm, that code works for me. what does the output look like if you do
a print_r on the $_REQUEST array on the exams2.php page?
Also, take a look at the foreach loop http://www.php.net/foreach .
I think you might like that for looping through your arrays