Related Data Display related column value based on relation

When your main table contains the fields related to other tables then you can use the related data function to easily get data from other tables and also display as list in the forms. For example, if you want to display crud for "student" table containing class_id which is related to "class" table (columns class_id, class_name ) then you can easily display class_name instead of class_id using the related data. Also, it converts the field class_id to dropdown with display field text as "class_name" and value saved will be "class_id".

In previous version, this can be done using join between main table and other tables and defining the field type and binding that field using the fielddatabinding function. Now this can be done using a single line.

Please note that it works on the main table field related to the other tables, it doesn't work on joined table. Also, currently it is supported by Mysql only. We will add for other database also in future versions.

  
                                $pdocrud = new PDOCrud();
                                $pdocrud->crudTableCol(array("student_id","register_number","first_name","last_name","class_id"));//optional
                               /**
                               * Get related column data 
                               * @param   string   $mainTableCol                            Column name of the main table
                               * @param   string   $relTable                                Related table name
                               * @param   mixed    $relTableCol                             Matching related table columns
                               * @param   mixed    $relDisplayCol                           Related table column to be display
                               * @param   mixed    $fieldType                               Field type to be displayed for that field, default is "select", if empty, then textarea will be shown
                               * return   object                                            Object of class
                               */
                               $pdocrud->relatedData('class_id','class','class_id','class_name');
                               echo $pdocrud->dbTable("student")->render();
                        

Student

Showing 1 to 4 of 4 entries

# Student id Register number First name Last name Class id Actions
1 13 R0001 Jon Duo first
2 14 R0002 David Mars second
3 15 R0003 Mark Tasr third
4 16 R0004 Kelvin Kale fourth
# Student id Register number First name Last name Class id Actions