merge student name under the same company names and only show the selected student name under that particular company
I have got something like this as a prototype and i wanted it sorted according to this. but now my code have all the student name under different companies. how i can fetch them according when开发者_运维问答 this student and this company is link and only fetch them out like that? no codes done yet though.
You first select your company names using a query something like this:
select * from companytable order by year
Now you have the result set in array. Now when looping through array, you need another query for students under each company. Something like this:
select * from studenttable where company_id = $row->company_id order by student_anme
You again run a loop within parent loop and echo out the students under each company and so on.
I assume you have tables constructed that way.
the problem description is realy bad
SELECT * FROM students AS s
LEFT JOIN company c ON c.id = s.company_id
ORDER BY c.year DESC
精彩评论