mysqli_fetch_array does not know the return value of join select statement mysql php

I am working on data base system which i need to return the values from data base and out put them in a table form and i use join statement when i am trying to run the web page it comes up with this error message:

Notice: Undefined index: student.name in ...

Here is part of my code

   if (isset($_POST['submit_exam'])){
        $gerayesh_id=mysqli_real_escape_string($cnn,$_POST['gerayesh_id']);
        $exam_number=mysqli_real_escape_string($cnn,$_POST['exam_number']);
        $query="SELECT student.name , student.lname , student.student_id , exam.exam_number , exam.exam_id FROM";
        $query.=" exam  JOIN exam_register  on exam.exam_id=exam_register.exam_id";
        $query.=" JOIN student  on student.student_id=exam_register.student_id";
        $query.=" WHERE (exam.gerayesh_id=$gerayesh_id)";
        $query.=" AND (exam.exam_number=$exam_number)";
        $result=mysqli_query($cnn,$query);
        if($result){
        echo "<form method=\"post\" action=\"manage_add_result.php\"  target=\"_blank\" style=\"float:right;\">";
    echo "<table >";
        echo    "<tr>";
                echo "<th>&#1606;&#1575;&#1605;</th>";
                echo "<th>&#1606;&#1575;&#1605; &#1582;&#1608;&#1575;&#1606;&#1608;&#1575;&#1583;&#1711;&#1740;</th>";
                echo"<th>&#1588;&#1605;&#1575;&#1585;&#1607; &#1570;&#1586;&#1605;&#1608;&#1606;</th>";
                echo "<th>&#1575;&#1606;&#1578;&#1582;&#1575;&#1576;</th>";


            echo"</tr>";
    while($row=mysqli_fetch_array($result) ){

            echo"<tr>";
            echo"<td>{$row['student.name']}</td>";
            echo "<td>{$row['student.lname']}</td>";
            echo "<td>{$row['exam.exam_number']}</td>";
            echo "<td><input type=\"checkbox\" value=\" {$row['student.student_id']}\" name=\"student_id\"/></td>";
            echo "<input type=hidden name=exam_id value=\"{$row['exam.exam_id']}\">";


            echo"</tr>";        

     }
    // $row=mysqli_fetch_array($result);

     echo"</table>";
         echo "<input type=\"submit\" name=\"submit_student\" value=\"&#1570;&#1662;&#1604;&#1608;&#1583; &#1705;&#1575;&#1585;&#1606;&#1575;&#1605;&#1607;;\">";
     echo "</form>";



        } else{echo mysqli_error($cnn);}


    }

the error undefined index shows for all of my variables that should be shown in table i am wondering what can i do thanks for your time

Upvotes: 0

Views: 281

Answers (1)

Barmar
Barmar

Reputation: 781592

The keys in the associative array are just the column names, not table.column. So use:

        echo"<td>{$row['name']}</td>";
        echo "<td>{$row['lname']}</td>";
        echo "<td>{$row['exam_number']}</td>";
        echo "<td><input type=\"checkbox\" value=\" {$row['student_id']}\" name=\"student_id\"/></td>";
        echo "<input type=hidden name=exam_id value=\"{$row['exam_id']}\">";

If you return columns from different tables that have the same name, you'll need to give them aliases to be able to reference both of them. This isn't an issue with your query, where all the column names in the SELECT clause are different.

Upvotes: 1

Related Questions