PHP Mysql joinget results

PhiX

New Member
I have 3 tables the subject, student, and relation
The following are sample datastudents tableid name1 John2 Doe3 Janesubject tableid subject1 Math2 Science3 Englishrelation tableid student_id subject_id1 1 12 1 33 2 14 1 2in this case sudent with id=1 has 3 subjects. How can I get result like this?student name is Johnsubjects are:MathScienceEnglishI already get the values for student, what I'm trying to do is get his subject to be shown by user.I'm totally confused using join tables. I'm a newbie in php and I start learning this last week. I'm getting an error on my code. Please help.
My Cuurent code is this:<?php//mysql connection$query = " SELECT *,* FROM relation, subject on subject_id = id WHERE student_id = $student_id";$result = mysql_query($query);?>Student name is <?php echo $name ?><br />Subjects are:<br /><?phpwhile($row = mysql_fetch_array($result)) { echo $row["subject"];}?>
 
Back
Top