This topic is locked

Picking ID field from Mastertable

11/20/2005 6:28:06 AM
PHPRunner General questions
F
flatdoggy author

I have two tables wich contain details about students and teacher like:
Teacher: TeacherID, Name, Age, Gender

Student: StudentID, TeacherID, Age, Gender, Class, [Teacher Name]
The question:

I add records to the Student table. How can I get the value of [Teacher Name] to be insterted in The Student table While I select the TeacherID. Teacher Nameis ofcourse the Namefield in Teacher table
Meaning: I select the value of TeacherID from the lookuplist referring to Teacher. But I need The [Teacher Name] To be insterted automatically in the value.
Also my table for acces to the database has more then 2 entries. I'd like to be 1 or more added during adding of records.
So My Accestable is like this: ID, Name, Full Name, email.

When a user adds a record I like his ID to be shown in the record.

Is this possible?

Sergey Kornilov admin 11/21/2005

Hi,
you can do the following to implement this:

  1. Open Datasource tabletab in PHPRunner, select Studenttable and check off Display master table info box.
  2. Proceed to Formatting tab, click Edit format for [Teacher Name] field and enter the default value:
    @$_SESSION["TeacherName"]



3. Build the pages.

4. Open student_list.php file with a text editor and locate DisplayMasterTableInfo function there.

Find this line inside it:

$data=db_fetch_array($rsMaster);



and insert this line just after:

$_SESSION["TeacherName"]=$data["Teacher Name"];


You can do something similar for ID field from Access table.

To fill a corresponding $_SESSION value you should modify login.phpfile and insert your line just after this fragment of code:

$_SESSION["UserID"] = @$_POST["username"];

$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;

F
flatdoggy author 11/23/2005

Ok this answer seems clear but maybe I didn't ask my question the right way.

The trouble I run into is I actually have three tables.

1 Teacher

2 Student

3 Examresults
Getting a default vaule from Teacher into Student is possible As I set TeacherNameas the value for Master/Details

Teacher: TeacherID, Name, Age, Gender

Student: StudentID, TeacherID, Age, Gender, Class, TeacherName



My current problem is That I have the table Teacher set to master for table Student and I need to get a value from table Student (StudentID) into table Examresults by default when adding a record into Examresults. Is this still possible since I can't anounce more then one Master/Details relation to one table?

I need the relation Teacher/Examresults so when I select a Teacher I get the corresponding Exanresults from Student that did an exam with that partivulair Teacher. So this is what the tables look like now:

Teacher: TeacherID, Name, Age, Gender [Mastertable]

Student: StudentID, Name, Age, Gender, TeacherName

Examresult: StudentID, TeacherID ExamResult [Detailstable]
So the problem I face is that I also like to have Student.StudentID be placed into Examresults.StudentID

Where I no longer can make a MasterDetail relation with Student and Examresults because I made a MasterDetail between Teacher and Examresults. Or should I set Examresult to master for Both Teacher and Student?

Sergey Kornilov admin 11/23/2005

Hi,
you can not set two master tables for one detail table.
Maybe you can create two different PHPRunner project based on your tables and put them to separate folders on your server to implement different functionalities you need.