Index

Some PAD pages based on the Classic Models database, as found on www.mysqltutorial.org

To demonstrate the PAD Table functionality

Configuration

PHP
_inits.php
<?php

// The whole of this application is this file: the tables, what identifies a row of each, and
// how they reach one another. Every page beside it is a template that walks those relations
// without writing a join.
//
// Recovered from commit ac148cccd, where it declared its tables in $padTables and gave each
// relation an empty array. The select subsystem reads $padSelect now, and a relation names
// the field it is followed by, so it is written in that form here.

$padSelect ['customers'] = [ 'db' => 'customers', 'key' => 'customerNumber', 'order' => 'customerName' ];
$padSelect ['employees'] = [ 'db' => 'employees', 'key' => 'employeeNumber', 'order' => 'lastName,firstName'];
$padSelect ['offices'] = [ 'db' => 'offices', 'key' => 'officeCode' ];
$padSelect ['details'] = [ 'db' => 'orderdetails', 'key' => 'orderNumber,productCode', 'order' => 'orderLineNumber' ];
$padSelect ['orders'] = [ 'db' => 'orders', 'key' => 'orderNumber' ];
$padSelect ['payments'] = [ 'db' => 'payments', 'key' => 'customerNumber,checkNumber' ];
$padSelect ['lines'] = [ 'db' => 'productlines', 'key' => 'productLine' ];
$padSelect ['products'] = [ 'db' => 'products', 'key' => 'productCode' ];

// A relation is the field of the base table that holds the key of the other one.

$padRelations ['products'] ['lines'] = 'productLine';
$padRelations ['payments'] ['customers'] = 'customerNumber';
$padRelations ['orders'] ['customers'] = 'customerNumber';
$padRelations ['details'] ['orders'] = 'orderNumber';
$padRelations ['details'] ['products'] = 'productCode';
$padRelations ['employees'] ['offices'] = 'officeCode';
$padRelations ['customers'] ['employees'] = 'salesRepEmployeeNumber';

// Virtual tables: the employees table under another name, so that an employee has a manager
// and a manager has a boss without any of them being a table of its own. Each is declared
// like any other table, over the same db, and related by the field that holds the other's
// key - an employee's reportsTo holds their manager's employeeNumber.
//
// The declaration used to read [ 'table' => 'employees', 'key' => 'reportsTo' ], which the
// select subsystem no longer understands: it wants the table in $padSelect and the relation
// as base field => related field. Written the old way the relation was silently ignored and
// every employee came out as their own manager.

$padSelect ['sales'] = [ 'db' => 'employees', 'key' => 'employeeNumber', 'order' => 'lastName,firstName' ];
$padSelect ['managers'] = [ 'db' => 'employees', 'key' => 'employeeNumber', 'order' => 'lastName,firstName' ];
$padSelect ['bosses'] = [ 'db' => 'employees', 'key' => 'employeeNumber', 'order' => 'lastName,firstName' ];

$padRelations ['customers'] ['sales'] = [ 'salesRepEmployeeNumber' => 'employeeNumber' ];
$padRelations ['employees'] ['managers'] = [ 'reportsTo' => 'employeeNumber' ];
$padRelations ['managers'] ['bosses'] = [ 'reportsTo' => 'employeeNumber' ];

?>

offices

PHP
HTML
offices.pad
Result
<table>
<tr>
<td>

<table border=1>
{offices sort}
{employees}
<tr>
<td> {$city} </td>
<td> {$lastName}, {$firstName} </td>
</tr>
{/employees}
{/offices}
</table>

</td> <td> &nbsp; </td> <td>

<table border=1>
{employees}
{offices}
<tr>
<td> {$lastName}, {$firstName} </td>
<td> {$city} </td>
</tr>
{/offices}
{/employees}
</table>

</td>
</tr>
</table>
San Francisco Bow, Anthony
San Francisco Firrelli, Jeff
San Francisco Jennings, Leslie
San Francisco Murphy, Diane
San Francisco Patterson, Mary
San Francisco Thompson, Leslie
Boston Firrelli, Julie
Boston Patterson, Steve
NYC Tseng, Foon Yue
NYC Vanauf, George
Paris Bondur, Gerard
Paris Bondur, Loui
Paris Castillo, Pamela
Paris Gerard, Martin
Paris Hernandez, Gerard
Tokyo Kato, Yoshimi
Tokyo Nishi, Mami
Sydney Fixter, Andy
Sydney King, Tom
Sydney Marsh, Peter
Sydney Patterson, William
London Bott, Larry
London Jones, Barry
 
Bondur, Gerard Paris
Bondur, Loui Paris
Bott, Larry London
Bow, Anthony San Francisco
Castillo, Pamela Paris
Firrelli, Jeff San Francisco
Firrelli, Julie Boston
Fixter, Andy Sydney
Gerard, Martin Paris
Hernandez, Gerard Paris
Jennings, Leslie San Francisco
Jones, Barry London
Kato, Yoshimi Tokyo
King, Tom Sydney
Marsh, Peter Sydney
Murphy, Diane San Francisco
Nishi, Mami Tokyo
Patterson, Mary San Francisco
Patterson, Steve Boston
Patterson, William Sydney
Thompson, Leslie San Francisco
Tseng, Foon Yue NYC
Vanauf, George NYC

employees_1

PHP
HTML
employees_1.pad
Result
<table border=1>
<tr>
<td> employee </td>
<td> manager </td>
<td> boss </td>
</tr>
{employees}
<tr>
<td> {$lastName},
{$firstName}
({$employeeNumber})
</td>
<td> {managers}
{$lastName},
{$firstName}
({$employeeNumber})
{/managers}
</td>
<td> {managers}
{bosses}
{$lastName},
{$firstName}
({$employeeNumber})
{/bosses}
{/managers}
</td>
</tr>
{/employees}
</table>
employee manager boss
Bondur, Gerard (1102) Patterson, Mary (1056) Murphy, Diane (1002)
Bondur, Loui (1337) Bondur, Gerard (1102) Patterson, Mary (1056)
Bott, Larry (1501) Bondur, Gerard (1102) Patterson, Mary (1056)
Bow, Anthony (1143) Patterson, Mary (1056) Murphy, Diane (1002)
Castillo, Pamela (1401) Bondur, Gerard (1102) Patterson, Mary (1056)
Firrelli, Jeff (1076) Murphy, Diane (1002)
Firrelli, Julie (1188) Bow, Anthony (1143) Patterson, Mary (1056)
Fixter, Andy (1611) Patterson, William (1088) Patterson, Mary (1056)
Gerard, Martin (1702) Bondur, Gerard (1102) Patterson, Mary (1056)
Hernandez, Gerard (1370) Bondur, Gerard (1102) Patterson, Mary (1056)
Jennings, Leslie (1165) Bow, Anthony (1143) Patterson, Mary (1056)
Jones, Barry (1504) Bondur, Gerard (1102) Patterson, Mary (1056)
Kato, Yoshimi (1625) Nishi, Mami (1621) Patterson, Mary (1056)
King, Tom (1619) Patterson, William (1088) Patterson, Mary (1056)
Marsh, Peter (1612) Patterson, William (1088) Patterson, Mary (1056)
Murphy, Diane (1002)
Nishi, Mami (1621) Patterson, Mary (1056) Murphy, Diane (1002)
Patterson, Mary (1056) Murphy, Diane (1002)
Patterson, Steve (1216) Bow, Anthony (1143) Patterson, Mary (1056)
Patterson, William (1088) Patterson, Mary (1056) Murphy, Diane (1002)
Thompson, Leslie (1166) Bow, Anthony (1143) Patterson, Mary (1056)
Tseng, Foon Yue (1286) Bow, Anthony (1143) Patterson, Mary (1056)
Vanauf, George (1323) Bow, Anthony (1143) Patterson, Mary (1056)

employees_2

PHP
HTML
employees_2.pad
Result
<table border=1> 
<tr>
<td> employee </td>
<td> manager </td>
<td> boss </td>
</tr>
{employees}
<tr>
<td> {$lastName}, {$firstName} ({$employeeNumber}) </td>
{managers}
<td> {$lastName}, {$firstName} ({$employeeNumber}) </td>
{bosses}
<td> {$lastName}, {$firstName} ({$employeeNumber}) </td>
{/bosses}
{/managers}
</tr>
{/employees}
</table>
employee manager boss
Bondur, Gerard (1102) Patterson, Mary (1056) Murphy, Diane (1002)
Bondur, Loui (1337) Bondur, Gerard (1102) Patterson, Mary (1056)
Bott, Larry (1501) Bondur, Gerard (1102) Patterson, Mary (1056)
Bow, Anthony (1143) Patterson, Mary (1056) Murphy, Diane (1002)
Castillo, Pamela (1401) Bondur, Gerard (1102) Patterson, Mary (1056)
Firrelli, Jeff (1076) Murphy, Diane (1002)
Firrelli, Julie (1188) Bow, Anthony (1143) Patterson, Mary (1056)
Fixter, Andy (1611) Patterson, William (1088) Patterson, Mary (1056)
Gerard, Martin (1702) Bondur, Gerard (1102) Patterson, Mary (1056)
Hernandez, Gerard (1370) Bondur, Gerard (1102) Patterson, Mary (1056)
Jennings, Leslie (1165) Bow, Anthony (1143) Patterson, Mary (1056)
Jones, Barry (1504) Bondur, Gerard (1102) Patterson, Mary (1056)
Kato, Yoshimi (1625) Nishi, Mami (1621) Patterson, Mary (1056)
King, Tom (1619) Patterson, William (1088) Patterson, Mary (1056)
Marsh, Peter (1612) Patterson, William (1088) Patterson, Mary (1056)
Murphy, Diane (1002)
Nishi, Mami (1621) Patterson, Mary (1056) Murphy, Diane (1002)
Patterson, Mary (1056) Murphy, Diane (1002)
Patterson, Steve (1216) Bow, Anthony (1143) Patterson, Mary (1056)
Patterson, William (1088) Patterson, Mary (1056) Murphy, Diane (1002)
Thompson, Leslie (1166) Bow, Anthony (1143) Patterson, Mary (1056)
Tseng, Foon Yue (1286) Bow, Anthony (1143) Patterson, Mary (1056)
Vanauf, George (1323) Bow, Anthony (1143) Patterson, Mary (1056)

orders

PHP
HTML
orders.pad
Result
<table border=1>

{customers $customerNumber = 495}

{orders}

{details}

{products}

{lines}

<tr>
<td> {$customerNumber} </td>
<td> {$customerName} </td>
<td> {$orderNumber} </td>
<td> {$orderDate} </td>
<td> {$orderLineNumber} </td>
<td> {$productName} </td>
<td> {$productLine} </td>
</tr>

{/lines}

{/products}

{/details}

{/orders}

{/customers}

</table>


495 Diecast Collectables 10207 2003-12-09 1 1970 Triumph Spitfire Classic Cars


495 Diecast Collectables 10207 2003-12-09 2 1950's Chicago Surface Lines Streetcar Trains


495 Diecast Collectables 10207 2003-12-09 3 1992 Porsche Cayenne Turbo Silver Classic Cars


495 Diecast Collectables 10207 2003-12-09 4 1970 Dodge Coronet Classic Cars


495 Diecast Collectables 10207 2003-12-09 5 Diamond T620 Semi-Skirted Tanker Trucks and Buses


495 Diecast Collectables 10207 2003-12-09 6 1998 Chrysler Plymouth Prowler Classic Cars


495 Diecast Collectables 10207 2003-12-09 7 1957 Chevy Pickup Trucks and Buses


495 Diecast Collectables 10207 2003-12-09 8 1958 Chevy Corvette Limited Edition Classic Cars


495 Diecast Collectables 10207 2003-12-09 9 1954 Greyhound Scenicruiser Trucks and Buses


495 Diecast Collectables 10207 2003-12-09 10 1964 Mercedes Tour Bus Trucks and Buses


495 Diecast Collectables 10207 2003-12-09 11 1992 Ferrari 360 Spider red Classic Cars


495 Diecast Collectables 10207 2003-12-09 12 1962 Volkswagen Microbus Trucks and Buses


495 Diecast Collectables 10207 2003-12-09 13 1926 Ford Fire Engine Trucks and Buses


495 Diecast Collectables 10207 2003-12-09 14 1980’s GM Manhattan Express Trucks and Buses


495 Diecast Collectables 10207 2003-12-09 15 1962 LanciaA Delta 16V Classic Cars


495 Diecast Collectables 10207 2003-12-09 16 1940s Ford truck Trucks and Buses


495 Diecast Collectables 10243 2004-04-26 1 1939 Chevrolet Deluxe Coupe Vintage Cars


495 Diecast Collectables 10243 2004-04-26 2 1932 Model A Ford J-Coupe Vintage Cars