PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
wadesmart
Forum Commoner
Posts: 38 Joined: Sat Oct 02, 2004 10:10 pm
Location: US, Oklahoma
Contact:
Post
by wadesmart » 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:
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>
?>
And Page Two
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>
?>
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.
wadesmart
Forum Commoner
Posts: 38 Joined: Sat Oct 02, 2004 10:10 pm
Location: US, Oklahoma
Contact:
Post
by wadesmart » Thu Dec 02, 2004 2:48 pm
Tried this...
Code: Select all
<?php
<html><head></head>
<body>
<p>In Math the graders were in order:<br /></p>
<?php
var_dump($_POST);
echo '<pre>';
print_r($_POST);
while(list($_POST['Index'],$_POST['Value'])=each($_POST['Math'])) {
$GradeStudent[] = $_POST['Math'].$_POST['Index'] . $_POST['Student'].$_POST['Index'];
}
asort($GradeStudent);
while(list($_POST['Index'], $_POST['Value'])=each($GradeStudent)) {
echo '<br />'.$_POST['Student'].$_POST['Index'].' - '.$_POST['Math'].$_POST['Index'].'.';
}
?>
</body>
</html>
?>
rehfeld
Forum Regular
Posts: 741 Joined: Mon Oct 18, 2004 8:14 pm
Post
by rehfeld » Thu Dec 02, 2004 3:08 pm
the last time i helped you when we did the $_POST['car-'.$i] type stuff,
we were not using arrays at all. we were just making a bunch of variables.
here you are using arrays, so you dont do that stuff anymore.
Code: Select all
<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>