0

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

Jim Carrey (0001)

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?

1
  • 1
    Post the expected output Commented Jul 14, 2015 at 6:12

2 Answers 2

1

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>";
Sign up to request clarification or add additional context in comments.

Comments

0

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?

1 Comment

I appreciate the help, its an assignment I had but couldn't figure out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.