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.
views:
48answers:
2
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
2009-12-17 08:40:26
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
2009-12-17 08:53:27
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
2009-12-17 09:00:25
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
2009-12-17 09:46:11
so, you call as many queries as the arrays length is ? really, REALLY, bad advise.
Kemo
2009-12-17 11:37:47
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
2009-12-17 08:47:48