I need to put info from my database into an html .
The problem is that my query doesn't work.
My tables are:
1) Students(id,name,email) 2) Lessons (id,title) 3) Marks (student_id,lesson_id,mark)
I have several questions: 1) What is wrong? 2) Do I need an extra field Marks.id to make it PRIMARY KEY, or I need to group Marks.student_id and Marks.lesson_id into PRIMARY KEY?
I need my table to look like this
+-------+--------+--------+---------------+
| S.name| Math |Biology | email |
+-------+--------+--------+--------+------+
| John | A | B | john@smith.com|
+-------+--------+--------+---------------+
| Emma | B | B | emma@stone.com|
+-------+--------+--------+---------------+
This is my query
$strSQL = SELECT Students.name,Students.email,Lessons.title, Marks.mark
FROM Marks
LEFT JOIN Students ON Students.id = Marks.student_id
LEFT JOIN Lessons ON Lessons.id = Marks.lesson_id
This is php code
$result = mysql_query($strSQL);
while($row = mysql_fetch_array($result)){
echo "<tr>
<td>".$row['Students.name']."</td>
<td>".$row['Marks.mark']."</td>
<td>".$row['Students.email']."</td>
</tr>";
}