A user's language is obscene. What should I do?
Troublesome complex fetching from database
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > Java Programming > Troublesome complex fetching from database 1 October 2001 05:58:22

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

Troublesome complex fetching from database

Kath 1 October 2001 05:58:22
 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->teach­ers assigned->teacher info?

Or teachers assigned->teacher info->schools->type­?

Right now I am doing the first, sorta.

- k

Add comment
Justin Garrett 1 October 2001 05:58:22 permanent link ]
 Try the following to organize your results. You'll have to check the table
names and typos etc.

$sql = "SELECT schooltypes.schoolt­ypes,
schools.schoolname,­
teachers.lastname,
teachers.tuserid
FROM schooltypes,
schools,
teachers,
teachers_school
WHERE schooltypes.typeid = schools.typeid
AND schools.schoolid = teachers_schools.sc­hoolid
AND teacher_schools.tus­erid = teachers.tuserid";

$result = /* perform query */;

while($row = mysql_fetch_object(­$result)){

$data[$row->schooltypes][$row->schoolname][] = "$row->tuserid
$row->lastname";

}

/* organize */

for(reset($data); $school_type = key($data); next($data)){
echo "$school_type<br><b­r>";
$schools = $data[$school_type];
for(reset($schools)­; $school_name = key($schools); next($schools)){
echo "$school_name<br><b­r>";
$teachers = $data[$school_type][$school_name];
$count = count($teachers);
for($i = 0; $i < $count; $i++){
echo "$teachers[$i]<br>";
}
}
}

--
Justin Garrett


"Kath" <kath@kathweb.net> wrote in message
news:002601c149f3$7­dec4000$82e53181@res­net.sunysb.edu...> 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,
"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
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->teach­ers assigned->teacher info?>
Or teachers assigned->teacher info->schools->type­?>
Right now I am doing the first, sorta.>
- k>


Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > Java Programming > Troublesome complex fetching from database 1 October 2001 05:58:22

see also:
[PATCH MM] (was Re: VMS (non-perl)…
[PATCH MM_VMS.pm@15662] disttest tweak…
vms_pipe_torture.t
пройди тесты:
see also:
How to strip DRM off iTunes M4P music…
How to transfer iTunes M4P music to…
How to import iTunes M4P music to…

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .