我有3个表女巫被称为学生和考试和exam_register考试表包含有关考试的信息,exam_register包含有关在exam_register注册一些考试的学生的信息我有student_id作为外键我需要返回学生谁签署了特定考试的数据,所以我尝试了这个
<?php
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 s.name , s.lname , s.student_id , e.exam_number e.exam_id FROM";
$query.=" exam e JOIN exam_register r on e.exam_id=r.exam_id";
$query.=" JOIN student s on s.student_id=r.student_id";
$query.=" WHERE (e.gerayesh_id=$gerayesh_id)";
$query.=" AND (e.exam_number=$exam_number)";
$result=mysqli_query($cnn,$query);
if($result){
echo "<form method=\"post\" action=\"mange_add_result.php\" 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['s.name']}</td>";
echo "<td>{$row['s.lname']}</td>";
echo "<td>{$row['e.exam_number']}</td>";
echo "<td><input type=\"checkbox\" value=\" {$row['s.student_id']}\" name=\"student_id\"/></td>";
echo"</tr>";
}
$row=mysqli_fetch_array($result);
echo"</table>";
//echo "<input type=\"hidden\" name=\"exam_id\" value=\"$row['e.exam_id']\">";
echo "<input type=\"submit\" name=\"submit\" value=\"آپلود کارنامه\">";
echo "</form>";
} else{echo mysqli_error($cnn);}
}
?>
但我得到错误并且说
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.exam_id FROM exam e JOIN exam_register r on e.exam_id=r.exam_id JOIN student s ' at line 1
感谢您的帮助
答案 0 :(得分:1)
在您的查询中,逗号丢失。
$query="SELECT s.name , s.lname , s.student_id , e.exam_number e.exam_id FROM";
^
将其更改为
$query="SELECT s.name , s.lname , s.student_id , e.exam_number, e.exam_id FROM";
答案 1 :(得分:0)
你忘了在e.exam_number之后和e.exam_id之前使用逗号(,)对字段进行saparate。