I have a scenario where I want to put php programming logic into the sql logic. Is this possible? Let me explain my scenario.
I have two tables, courses, and categories. Here's a dummed-down version of each:
Categories:
int id, int parent, string name
Courses:
int id, int parent, string name.
Now lets say in the categories table we have the following rows:
1 0 "English"
2 0 "Science"
3 2 "Chemistry"
4 2 "Physics"
Now Courses might have the following rows:
1 3 "chem101"
2 0 "english101"
3 4 "physics101"
4 2 "science101"
Lets say I wanted to get all the courses that are under the "science" category:
$resultset = mysql_query("select 'id' from categories where 'parent'=2");
foreach($resultset as $value){
mysql_query("select * from courses where 'parent'=$value")
//do something with the results
}
mysql_query("select * from courses where 'parent'=2")
I'm sure that there is a way to do this looping logic with one sql statement, but I can't figure out what that is. I did see something on "cursors" is that what would solve my problem?
Thanks,
Nick