Example 143: Customer Header-Detail
Description: This WebSmart PHP example makes a header and detail application to see a list of customers and their orders.
Customers (Header Program)
| Action |
Customer Number |
Customer Name |
Address 1 |
City |
Country |
|
1 |
Music by the Numbers |
7844 Franklin Blvd. |
Chicago |
US |
|
2 |
Up Tempo Distributors |
801 - 9558 Abbey Rd. |
Phoenix |
US |
|
3 |
OER Music |
301 10th Street NW |
Calgary |
CA |
|
4 |
Maritime Music |
3200 Capitol Blvd |
Olympia |
US |
|
5 |
Swingin' Strings |
2101 Louisiana Blvd NE |
Albuquerque |
US |
|
6 |
Cam's Country |
86 Bedford Street |
New York |
US |
|
7 |
The Rock Studio |
909 12th Street |
Sacramento |
US |
|
8 |
The Welsh Connection |
39302 Sunnyside Way |
Chicago |
US |
|
9 |
Fruit of the Lute |
7968 Vaughn Road |
Montgomery |
US |
|
10 |
Phil's Philharmonic |
5400 E Olympic Blvd |
Los Angeles |
US |
Header Program:
-
Start a new program named customer_header.php using the 'SQL Page at a Time Maint' template.
-
At the 'Additional Design Options' step, accept the default options.
-
At the 'File Maintenance Options' step, uncheck all options except 'Allow display of
full record'.
-
When prompted, add the file MU_CUSTF in XL_WEBDEMO and choose the fields CMCUST,
CMNAME, CMADR1, CMCITY and CMCOUNT. The wizard will also prompt you to select fields
for the single record display; choose any field (we won't be displaying this page anyway).
-
Change the 'A' tag for the 'display' action in the segment 'ListDetails' to this:
<a href="customer_detail.php?cmcust=$CMCUST">Orders</a>
Detail Program:
-
Start creating a new program named customer_detail.php using the 'SQL Record Listing' template.
-
Add the file MU_ORDHL1 from XL_WEBDEMO.
-
Choose the fields OHCUST, OHORD, OHDESC, OHORDT, OHSTAT and OHOTOT.
-
Add these lines to near the top of the program in your PHP:
// Global variables should be defined here
global $ww_custno;
// retrieve the customer number parameter
if (isset($_REQUEST['cmcust']))
$ww_custno = $_REQUEST['cmcust'];
This code will retrieve the customer number passed from the header program.
-
Modify the SQL query in the main function to filter records based on the
customer number passed from the header program. The query should look like:
$query = 'select OHCUST, OHORD, OHDESC, OHORDT, OHSTAT, OHOTOT
from XL_WEBDEMO/MU_ORDHL1 where OHCUST = $ww_custno';
-
Add formatting to the selected date field (OHORDT) using the strftime() function.
Before outputting the detail information include the line to format the date as
follows:
while ($row = db2_fetch_assoc($stmt))
{
// set color of the line
xl_set_row_color('altcol1', 'altcol2');
$OHORD = $row["OHORD"];
$OHDESC = $row["OHDESC"];
$OHORDT = $row["OHORDT"];
$OHSTAT = $row["OHSTAT"];
$OHOTOT = $row["OHOTOT"];
$OHORDT = strftime("%Y/%m/%d", strtotime($OHORDT));
wrtseg("ListDetails");
}
-
Generate the program. To run it launch the "header" program that will pass the
customer number as a parameter to the "details" program.
|