I have 3 tables the subject, student, and relation
The following are sample data
students table id name 1 John 2 Doe 3 Jane subject table id subject 1 Math 2 Science 3 English relation table id student_id subject_id 1 1 1 2 1 3 3 2 1 4 1 2
in this case sudent with id=1 has 3 subjects. How can I get result like this?
student name is John subjects are: Math Science English
I 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 />
<?php
while($row = mysql_fetch_array($result)) {
echo $row["subject"];
}
?>