Reputation: 39
I've been struggling getting an array information to match and get posted/get onto another page.
How is it possible to match the $name so that it will display the rest of the array to the appropriate name on the new page?
I have spent several days doing various combinations and tries without success, any assistance will be much appreciated!
This is the array I'm retrieving the information:
<?php //This is the p6_Assignment2.php
$students = array(
"Jim, Carrey" => array( "0001" => array("Class1" => array("grade1" => 33, "grade2" => 33, "grade3" => 34))),
"John, Connor" => array( "0002" => array("ClassB" => array("grade1" => 20, "grade2" => 60, "grade3" => 20))),
"Anderson, Silva" => array( "0003" => array("ClassC" => array("grade1" => 40, "grade2"=> 30, "grade3" => 30)))
);
?>
The html data
<html>
<head>
<title>test</title>
</head>
<body>
<form action="p8_Assignment2.php" method="get">
<select name="selectPage">
<?php
include ('p6_Assignment2.php');
foreach ($students as $name => $id) {
?>
<option value="<?php echo $name ?>"> <?php echo $name ?> </option>;
<?php
}
?>
</select>
<input type="submit" value="Submit">
</form>
</body>
The 3rd File Where the data should show
<html>
<head>
<title>Results</title>
</head>
<body>
<?php
foreach($_POST as $name){
echo $name;
}
?>
</body>
apologies for missing this Expected Output
ClassC : 81% , ClassC : 44% , ClassC : 55% ,
UPDATE I have readjusted the problem above.
Now i still cant seem to access the array to display the information.
how is it possible to use the $_POST data, (in this case lets assume: "Jim, Carrey") and get the rest of the array for the specified user?
Upvotes: 0
Views: 53
Reputation: 10058
you should add your select tag also a name attribute
<select name="test">
<option value=1>option name to show to user</option>
<option value=2>another option name to show to user</option>
</select>
this will allow you the get the VALUE of the selected option. if the user selected option 2
you'll be able to see this by
<?php
echo $_GET['test']; //this will print 2
?>
btw, why do you need a structure of array=>array=>array=>array?
Upvotes: 0
Reputation: 31749
Without the name
of the input field you cannot access them in php
.
Add name
of the select
-
<select name="nameOfFoeld">
And also add the value
of option
-
echo "<option value='theValueOfOption'>".$name ." </option>";
Upvotes: 1