0
   <?php
      if(isset($_GET["groupe"]) && isset($_GET["examen"]))
      {
            require_once("fonctionstp.php");
            $groupeNumber =  $_GET["groupe"];
            $examenNumber = $_GET["examen"];

            $groupe = "";
            if($groupeNumber == 0){
                $groupe = $NotesGroupe1;
            }else if ($groupeNumber == 1){
                $groupe = $Notesgroupe2;    
            }

            if($groupe != ""){  
                $keys = array_keys($groupe);

                for($i = 0; $i < count($groupe); $i++){
                    $student= $groupe[$keys[$i]];
                    $prenom = $student[0];
                    $nom = $student[1];
                    $noteExam = $student[$examenNumber + 4];
                    echo $prenom. " " .$nom. " a eu " .$noteExam . "a 
                    l'examen.".$examenNumber + 1 . " !";
                }
            }  
       }        
   ?>

I have a simple form html that says, with one select that let you ( choose group 1 or 2. ) after that you have an another select that let you choose :

the first gradescore, the second grade score and the third grade score.

It means that I need to show to the user, the first and second name of the person in the Group 1 or 2 (Depend which they chosed) and one of the scores they took. I need to show every person in that group.

I have an another php files that is associative array

<?php
$NotesGroupe1 = array(
 "HARG200181" => array("Guillaume", "Harvey", "M", 36, 90, 70, 76),
 "CHAM010283" => array("Marc-André", "Charpentier", "M", 34, 80, 73, 96),
 "TREV290991" => array("Valérie", "Tremblay", "F", 26, 70, 71, 69),
 "PELL180584" => array("Laurence", "Pelletier", "F", 30, 65, 89, 76),
 "MALF110194" => array("Francis", "Maltais", "M", 20, 61, 50, 59),
 "GAUM220654" => array("Martine", "Gauthier", "F", 60, 65, 40, 76),
);
$NotesGroupe2 = array(
 "GIRM230383" => array("Marc-Olivier", "Girard", "M", 31, 75, 85, 56),
 "TREM300878" => array("Michel", "Tremblay", "M", 36, 50, 50, 55),
 "POID250468" => array("Diane", "Poitras", "F", 46, 61, 75, 59),
 "LEML180586" => array("Laurence", "Lemieux", "F", 31, 80, 89, 100),
 "VANL130395" => array("Jeff", "Van Cleef", "M", 19, 61, 68, 33)
);  

?>

The problem is when I test it on my own. When I submit it gives me 1 !1 !1 !1 !1 !1 ! I'm missing something.

1 Answer 1

2

You have a "A non-numeric value encountered", because you are missing to wrap your addition with brackets:

for($i = 0; $i < count($groupe); $i++){
    $student= $groupe[$keys[$i]];
    $prenom = $student[0];
    $nom = $student[1];
    $noteExam = $student[$examenNumber + 4];
    echo $prenom. " " .$nom. " a eu " .$noteExam . "a 
    l'examen." . ($examenNumber + 1) . " !";
}

Because:

$prenom. " " .$nom. " a eu " .$noteExam . "a l'examen." . $examenNumber

is a string, then, by adding + 1, you're trying to add a string with a number. Finally, you add " !", so it's converted to a string. So you get:

1 ! 
Sign up to request clarification or add additional context in comments.

4 Comments

wow. Thank you so much. I appreciate the time you took the answer to this question.
@EngjëllBislimi You're welcome :) Don't forget to close your question if an answer solves your problem. Thanks :) meta.stackexchange.com/questions/5234/…
hmm i am not sure how to actually close it. sorry
@EngjëllBislimi No worries :) See the following link : meta.stackexchange.com/questions/5234/… Thank you!

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.