Troublesome complex fetching from database
| From: | Kath | Date: | Sun, 30 Sep 2001 21:04:27 +0000 |
| Subject: | Troublesome complex fetching from database | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-69386@lists.php.net to get a copy of this message | ||
Quite an interesting quandry I have.
What I have is this:
Table schooltypes:
(typeid is a unique# iding the type, schooltypes is the type of school, say
"Elementary School" or "High School")
| typeid | schooltypes |
Table schools:
(typeid is the type the school falls under, schoolid is the unique# iding
the school, schoolname is the general name like "Park Shore High School")
| typeid | schoolid | schoolname |
Table teachers:
(tuserid is their unique id, salutation is the Mr/Mrs/Miss/Ms/Dr, last name
is well, duh :))
| tuserid | salutation | last name |
Table teachers_schools:
(tuserid is the teacher's id, next to the school they are assigned to. Note
the possiblity for a teacher assigned to more than one school (hello,
cutbacks and skeleton budgets)).
| tuserid | schoolid |
What I need to be able to do is list all this information as such:
School type:
+ School 1
- Teacher and their Teacher ID
- Teacher and their Teacher ID
+ School 2
- Teacher and their Teacher ID
- Teacher and their Teacher ID
- Teacher and their Teacher ID
+ School 3
- Teacher and their Teacher ID
- Teacher and their Teacher ID
Another School Type:
+ School 5
- Teacher and their Teacher ID
- Teacher and their Teacher ID
+ School 7
- Teacher and their Teacher ID
- Teacher and their Teacher ID
Currently, I AM able to list the school type and the school correctly.
However, when I come to listing the teachers in the school, every teacher is
listed under every school, some more than one time.
Any ideas/code snips on how to do this?
In what direction should be I solving this?
Going from type->school->teachers assigned->teacher info?
Or teachers assigned->teacher info->schools->type?
Right now I am doing the first, sorta.
- k