Tutorial - Master/Detail

In this tutorial we will show you how to setup Master/Detail table view in PHPMaker. We will use the demo database for demonstration.

In the demo, there are two tables called "orders" and "orderdetails". We will set up the master/detail relation between these two tables.

Fields in Table "orders"

Fields in Table "orderdetails"

 

Steps to Setup Master/Detail Records

1. Loading PHPMaker

Open PHPMaker and connect to the demo database.

2. Setting up Master/Detail Relationship

Select either the master or detail table in the Database tree view (the left pane). In this example, we choose the master table - "orders" table. The Table Setup page is displayed in the right pane.

Then in [Master/Detail] panel at the bottom right corner of the page, click [Modify...] to bring up the visual master/detail relationship editor. Drag the detail table from the table list on the left to the diagram on the right.

Then create a relationship between them by dragging from the master field (key field in master table) to the detail field (foreign key field in the detail table).

If there are more linked field, repeat the step until all the relationships are setup. In this tutorial, we only have one detail field (`orderdetails`.`OrderID`) and one master field (`orders`.`OrderID`).

PHPMaker supports multiple master/detail, if the table has other master tables or detail tables, just repeat above process. In this example, we have only one master/detail relationship, so we click [OK] to confirm. The master/setail relationship is setup.

If you want to enable Master/Detail-Add and/or Master/Detail-Edit, enable Master/Detail-Add and/or Master/Detail-Edit for the detail table in the Table Setup page:

If you have the YUI Container or PreviewRow extension (for registered users only) and want to enable detail record preview by Ajax, you can click Tools->Extension to enable it. Also see Third-Party Tools.

Note: The Detail Record Preview feature works best when the number of the fields and number of records are not too many so the size of the preview area will not be too large. Otherwise the preview area may exceed the browser area and therefore the detail records cannot be viewed completely at a glance. Or the preview area will be too wide that it covers the detail table link and therefore the preview area can be hidden by moving the mouse cursor from the link.

3. PHP Script Generation

Click the [Generate PHP] icon to go to the [Generate] tab, click the [Generate] button. PHPMaker will generate the required PHP scripts automatically.

4. Running the PHP Application

Click on the link to the "orders" table, there will be a new column of "orderdetails..." which links to the "orderdetails " table. Click on the link to access the order details for the selected order.

If you have enabled YUI Container extension, move your mouse cursor over the "orderdetails..." link and you'll see detail records preview:

Click the "orderdetails" link, the List page for the detail table "orderdetails" will be shown. To add, delete, edit or view records in the Detail table, simply click on the corresponding links in the page.

Click "Back to Master Page" to go back to the master page, click the "Edit" or "Copy" link under the "orderdetails" link, or click the "Add orders/orderdetails", the Master/Detail-Add or Master/Detail-Edit page (actually the Add/Edit page for the master table with Grid-Add/Edit page for the detail table) will be shown. You can enter one master record with a number of detail records. For example, Master/Detail-Edit:

In Master/Detail-Add/Edit mode, you can click "Add Blank Row" or "Delete" to add or delete rows wiithout refreshing the page. Note this feature is implemented by JavaScript, newer version of browsers are required.

 

 

 ©2002-2012 e.World Technology Ltd. All rights reserved.