Help with Array and variables
Posted: Thu Dec 02, 2004 1:30 pm
Im have been working on understanding arrays but getting the information back out is difficult.
Here is a tutorial I have been working one.
Page One:
And Page Two
Im have another script I got help on but its not helping me with this one. I do not understand how to get the $Index to be correct. It produces errors.
Here is a tutorial I have been working one.
Page One:
Code: Select all
<?php
<html><head></head>
<body>
<?php
echo"<form method='post' action='exam2.php'>";
$Student = array("Albert Einstein", "Ivan The Terrible", "Napoleon", "Simon Bolivar", "Issac Newton");
while (list(,$Name)=each($Student)) {
echo "What grade did $Name get in Math?";
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 F</option>
</select>";
echo "<br /><br />";
echo "<input type='hidden' name='Student[]' value='$Name'>";
}
echo "<input type='submit'></form>";
?>
</body>
</html>
?>Code: Select all
<?php
<html><head></head>
<body>
<p>In Math the graders were in order:<br /></p>
<?php
while(list($Index,$Value)=each($_POST['Math'])) {
$GradeStudent[] = $_POST['Math'.$Index] . $_POST['Student'.$Index];
}
asort($GradeStudent);
while(list($Index, $Value)=each($GradeStudent)) {
echo '<br />'.$_POST['Student'.$Index].' - '.$_POST['Math'.$Index].'.';
}
?>
</body>
</html>
?>