Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » Display field from related table
Re: Display field from related table [message #299 is a reply to message #298] Wed, 04 October 2006 04:44 Go to previous messageGo to previous message
AJM is currently offline  AJM
Messages: 2367
Registered: April 2006
Location: Surrey, UK
Senior Member
To answer your question about the formatted teacher name which appears in the lesson_list screen, first go to the Data Dictionary and take a look at the definition of the 'teacher_id' column in the 'crs_lesson' table. You will see that the control type is 'dropdown list' and the option list is 'teacher_id'. In the '_cm_getExtaData()' method in the 'crs_lesson' class you will see where it calls the 'getValRep()' method on an instance of the 'crs_teacher' class to obtain the contents of an array of data which it loads into $this->lookup_data['teacher_id']. If you examine the '_cm_getValRep()' method in the 'crs_teacher' class you will see how this array is constructed. When a dropdown list control is read-only, such as in a LIST screen, the entire dropdown list is not displayed, but the selected entry from the list is. That is how 'teacher_id' is automatically shown as the teacher's name.

To achieve the same sort of effect without using a dropdown list control is easy. Basically it requires a JOIN, which can be performed in one of two ways as outlined in http://www.tonymarston.net/php-mysql/infrastructure-faq.html #faq18a and http://www.tonymarston.net/php-mysql/infrastructure-faq.html #faq18b.

To get the framework to perform the JOIN automatically you must go to the Data Dictionary and define the relationship between the two tables, as documented in http://www.tonymarston.net/php-mysql/menuguide/dict_relation ship(upd).html. This is where you say 'tableA is related to tableB, and the primary key field(s) of tableA are linked to so-and-so foreign key field(s) of tableB'. Notice also on this screen there is a column called 'parent field'. This is where you tell the framework to include that field from the parent table when you retrieve occurrences from the child table. You can either pick a single field from the dropdown list, or you can select the keyword 'CALCULATED' and fill in the details for 'calculated field'. Don't forget to export any changes you make using http://www.tonymarston.net/php-mysql/menuguide/dict_table(ex port).html so that the table structure file is updated.

If you do not set up the relationship details in the Data Dictionary so that the framework can perform the JOIN automatically, then you will have to do it manually, as outlined in http://www.tonymarston.net/php-mysql/infrastructure-faq.html #faq08.

I hope this answers your question.


 
Read Message
Read Message
Read Message
Previous Topic: Creating filters
Next Topic: NULL string
Goto Forum:
  


Current Time: Mon Nov 18 09:16:11 EST 2024

Total time taken to generate the page: 0.01103 seconds