Presto-X Posted August 29, 2011 Share Posted August 29, 2011 Hello everyone, In the past I have done one query and loop the results then did another query within that loop, I'm guessing this is not the best way to do this, I'm guessing there is a way to do one query very mySQL and then loop all of the parent and child rows. So this is what I'm trying to do, I have 3 tables "categories", "courses", and "classes", categories is the parent to courses and courses is the parent to classes, I'm trying to loop the content of each of the tables out on the page. ie. something like this: Category 0 Course 0 Class 0 Class 1 Class 2 Class 3 Course 1 Class 0 Class 1 Course 2 Class 0 Class 1 Class 2 If anyone could point me in the right direction for the correct term to be searching for I'm sure I could find the answer, but right now I'm stumped, I have played around with JOIN and UNION and that did not end up giving the results I was looking for, it just added all of the data in to each of the rows and looped them out. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted August 29, 2011 Share Posted August 29, 2011 really depends on how you tables are set up.. but from first glance here I would suggest looking further into using a JOIN, depending on whether or not you have like fields.. you can use a LEFT JOIN or INNER JOIN most likely Quote Link to comment Share on other sites More sharing options...
fenway Posted August 29, 2011 Share Posted August 29, 2011 Yup -- a 3 table join, then pre-process the results for pretty output. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.