Reputation: 41
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>نام</th>";
echo "<th>نام خوانوادگی</th>";
echo"<th>شماره آزمون</th>";
echo "<th>انتخاب</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=\"آپلود کارنامه;\">";
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
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