Categories > TinyButStrong general >

Nested Queries

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Will Robertson
Date: 2003-06-28
Time: 00:38

Nested Queries

Ack... okay this question was asked in french... diddn't really understand the answer. Here's a more clear problem layout.

For theorhetical sake, let's say I'm building a database for a school. Now the school has classes in our first table

Classes:
-Class ID
-Class Title
-Class Description

Then we put our students in another table:
Students:
-Student ID
-Student Name
(for our example we don't need anymore entries on this table)

Now, our picklist table... (which tells us which student is enrolled where)
-Picklist ID
-Student ID (referenced to Student table)
-Class ID (referenced to Class table)

Now I want to display them as follows:
Student1
In Classes: Class1, Class2, Class3
Student2
In Classes: Class2, Class3
Student3
In Classes Class1, Class3
etc.

normally with php... first I'd run down and select what I needed from the students tables to get a student listing.

SELECT Student Name, Student ID FROM Student;

Then for each student, I would SELECT out his classes:

SELECT Class.Class Name FROM Class as Class AND Picklist as Picklist WHERE (Picklist.Student ID == $Student ID) AND (Class.Class ID == Picklist.Class ID)

How would I then create a TBS doc to display it?

(Yes I know the SQL entries here will not work, these were pulled out of my brain. I can think of at least 3 differn't situations where I will need to do similar things).




By: Skrol29
Date: 2003-06-28
Time: 01:35

Re: Nested Queries

Hello Will,

The answer is Clone Blocks.
That's exacly what they are made for.
Cone blocks are described in the manual at th chapter
HTML Side/Merge Blocks.

Here is how to do with your example:
HTML:
[stud;block=begin]
[stud.Name]
In Classes: [class;block=begin;p1=[stud.Student_ID]] [class.Class_Title], [class;block=end]
[stud;block=begin]

PHP:
$TBS->MergeBlock('stud',$cnx_id,'SELECT Student_ID,Student_Name FROM Students') ;

$TBS->MergeBlock('class',$cnx_id,'SELECT Class_Title FROM Classes INNER JOIN PickList ON (Classes.Class_ID=PickList.Class_ID) WHERE (Student_Id=%1%)') ;