php - Select from 3 tables MySQL -


i need put info database html .

the problem 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) wrong? 2) need field marks.id make primary key, or need group marks.student_id , marks.lesson_id primary key?

i need table this

+-------+--------+--------+---------------+ | s.name| math   |biology |    email      | +-------+--------+--------+--------+------+ | john  |      |  b     | john@smith.com|  +-------+--------+--------+---------------+ | emma  |  b     |  b     | emma@stone.com| +-------+--------+--------+---------------+ 

this query

$strsql = select students.name,students.email,lessons.title, marks.mark    marks    left join students on students.id = marks.student_id    left join lessons on lessons.id = marks.lesson_id 

this 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>";              } 

$query = "   select s.name       , s.email       , l.id       , l.title       , m.mark     marks m    join students s      on s.id = m.student_id     join lessons l      on l.id = m.lesson_id;  ";   $result = mysql_query($query) or die(mysql_error()); // testing   while($row = mysql_fetch_assoc($result)){     echo "<tr>           <td>".$row['name']."</td>           <td>".$row['email']."</td>           <td>".$row['id']."</td>                         <td>".$row['title']."</td>           <td>".$row['mark']."</td>          </tr>";               } 

note: might time stop using deprecated api.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -