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 |
';
}
PANEL='ListDetails'
{
DESC='Page body';
ITERATIONS='10';
DETAILS='
|
$CMCUST |
$CMNAME |
$CMADR1 |
$CMCITY |
$CMCOUNT |
';
}
PANEL='ListFooter'
{
DESC='Page footer';
DETAILS='
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>
-
Compile this program.
Detail Program:
-
Start creating a new program named customer_detail.php using the \'SQL Record Listing\' template.
-
Add the file MU_ORDHL1 in XL_WEBDEMO.
-
Add the file MU_CUSTF in XL_WEBDEMO.
-
Choose the fields 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\'];
-
Choose the fields OHORD, OHDESC, OHORDT, OHSTAT and OHOTOT.
-
Replace the existing display() function with this new function
function display()
{
// Make all global variables available here
foreach($GLOBALS as $arraykey=>$arrayvalue)
{
global $$arraykey;
}
/*
*
* Query to find the customer number, name, city, and country
*
*/
$query = "select CMCUST, CMNAME, CMCITY, CMCOUNT
from XL_WEBDEMO/MU_CUSTF
where CMCUST = $ww_custno";
// Fetch rows for page: relative to initial cursor
if (!($stmt = db2_exec($db2conn, $query)))
{
echo "<b>Error ".db2_stmt_error() .":".db2_stmt_errormsg(). "</b>";
die;
}
$row = db2_fetch_assoc($stmt);
$CMCUST = $row["CMCUST"];
$CMNAME = $row["CMNAME"];
$CMCITY = $row["CMCITY"];
$CMCOUNT = $row["CMCOUNT"];
/*
*
* Query to find the orders for the customer
*
*/
$query = "select OHORD, OHDESC, OHORDT, OHSTAT, OHOTOT, CMCUST, CMNAME, CMCITY, CMCOUNT
from XL_WEBDEMO/MU_CUSTF inner join XL_WEBDEMO/MU_ORDHL1 on OHCUST=CMCUST
where OHCUST = $ww_custno";
// Fetch rows for page: relative to initial cursor
if (!($stmt = db2_exec($db2conn, $query)))
{
echo "<b>Error ".db2_stmt_error() .":".db2_stmt_errormsg(). "</b>";
die;
}
wrtseg("ListHeader");
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"];
$mydate = strftime("%Y/%m/%d", strtotime($OHORDT));
wrtseg("ListDetails");
}
// closet the database connection
db2_close($db2conn);
wrtseg("ListFooter");
}
-
Compile this program and run the \'Customer Header\' program.
|