tags:

views:

48

answers:

2

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.

This

A: 

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.

Sarfraz
sorry but i dont understand "You again run a loop within parent loop and echo out the students under each company and so on."
ros
and i tried using ur this code and it gave me same company name but different students name in two rows. i wanted like one company name but the associated student under it. (:
ros
this is something really easy, but probably i can not explain you better. If i see your code, then i can suggest you also.
Sarfraz
so, you call as many queries as the arrays length is ? really, REALLY, bad advise.
Kemo
A: 

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
antpaw