Live Examples

Example 6: Create Master - Detail, Parent - Child tables

Creating Master-Detail, or namely Parent-Child tables, is very easy with phpGrid. Simply pass the SQL Select and the foreign key to the method set_masterdetail(). Yes, it requires only one line of code. Please refer to online document for additional information on this method.

$dg = new C_DataGrid($hostName, $userName, $password, $dbName);
 
$dg -> set_gridpath     ("include/");
$dg -> set_sql          ("SELECT * FROM Employees");
$dg -> set_sql_table    ("Employees");
$dg -> set_sql_key      ("EmployeeId");
 
// change column titles
$dg -> set_col_title    ("EmployeeId", "Employee ID");
$dg -> set_col_title    ("LastName", "Last Name");
$dg -> set_col_title    ("FirstName", "First Name");
 
// set background and mouse over color
$dg -> set_alt_bgcolor  ("#ffcc99, #ffccdd");
$dg -> set_onmouseover  ("yellow");
 
// hide a column
$dg -> set_col_hidden   ("Notes");
 
// create master/detail tables
$dg -> set_masterdetail("SELECT * FROM Sales",
"employeeId",
" AND price > 100");
  $dg -> display();