PDF='MAIN' { ATTRIBUTES='*' { PLATFORM='php.txt'; REPTYPE='1'; ATTACHED='0'; PROJECT='36'; OBJECTNAME='customer_detail.php'; LIBLOBJ='*FILES'; TITLE='Customer Detail Program'; WEBPATH='http://esdi.excelsystems.com/wsexmp/'; TARGETPATH='/www/zendcore/htdocs/examples'; FTPSITE='WS-Examples'; SET='46'; VERSION='4.00'; CRTBNUM='Revision 1811'; CRTTEMPLT='C:\\Program Files\\ESDI\\WebSmart\\Temp\\PHP-Record Listing.tpl'; SAVBNUM='Revision 2341'; LASTLOC='1'; VHTML='N'; LASTSAVE='5/27/2008 11:22:11'; OBJLIBRARY='XL_WEBEXMP'; SOURCELIBR='XL_WEBEXMP'; SOURCEFILE='QRPGLESRC'; REPSYSTEM='esdi520int'; } FTPREFINFO='*' { URL='192.168.0.100'; INITIALDIR='/www/zendcore/htdocs/examples'; FTPPORT='21'; PASSIVEMODE='1'; WEBPATH='http://esdi.excelsystems.com/webtest/'; } FILES='*' { FILE='MU_ORDHL1' { LIBRARY='XL_WEBDEMO'; ALIAS=''; RCDFORMAT='RORDERH '; LEVELID='1071025172821'; RFLEVELID='4E69C242A36A9'; EXTDS='0'; JOINTYPE='inner'; LINKS='*' { LINK='MU_CUSTF.CMCUST' { LINKTYPE='='; LINKFIELD='MU_ORDHL1.OHCUST'; } } } FILE='MU_CUSTF' { LIBRARY='XL_WEBDEMO'; RCDFORMAT='R_CUSTF '; LEVELID='1070921111624'; RFLEVELID='403ABD661EC5A'; EXTDS='0'; } } PANELS='*' { PANEL='ListHeader' { DESC='Page header'; DETAILS=' Example 143: Customer Header-Detail

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 (Details Program)

Name: $CMNAME
City: $CMCITY
Country: $CMCOUNT


'; } PANEL='ListDetails' { DESC='Page body'; ITERATIONS='10'; DETAILS=' '; } PANEL='ListFooter' { DESC='Page footer'; DETAILS='
Customer Number Order Number Purchase Order / Description Order Date Order Status Order Total
$OHCUST $OHORD $OHDESC $OHORDT $OHSTAT $OHOTOT
  1. Start a new program named customer_header.php using the \'SQL Page at a Time Maint\' template.


  2. At the \'Additional Design Options\' step, accept the default options.


  3. At the \'File Maintenance Options\' step, uncheck all options except \'Allow display of full record\'.


  4. 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).


  5. 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:

  1. Start creating a new program named customer_detail.php using the \'SQL Record Listing\' template.


  2. Add the file MU_ORDHL1 in XL_WEBDEMO.


  3. Add the file MU_CUSTF in XL_WEBDEMO.


  4. Choose the fields OHORD, OHDESC, OHORDT, OHSTAT and OHOTOT.


  5. 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\'];    
        
  6. Choose the fields OHORD, OHDESC, OHORDT, OHSTAT and OHOTOT.


  7. 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");	
    	
    }	   
        

Header Program Definition:   customer_header.phw
Detail Program Definition:   customer_detail.phw

Rate This Example

Did this knowledge base article help you to achieve your goal?  Yes  No  Don\'t Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

'; } } PREVIEWS='*' { PREVIEW='Main List' { SEG='ListHeader'; SEG='ListDetails' { REPEAT='10'; } SEG='ListFooter'; } } ACTIONS=' // Program Name: customer_detail.php // Program Title: Customer Detail Program // Created by: TMC // Template family: Idaho // Template name: List All Records in File // Purpose: // Program Modifications: // DB Connection code require(\'/esdi/websmart/v6.6/include/xl_functions001.php\'); $options = array(\'i5_naming\' => DB2_I5_NAMING_ON); global $db2conn, $ww_custno, $mydate; $db2conn = xl_db2_connect($options); if(!$db2conn) { die(\'Failed to connect to database!\'); } global $wsnum; // This code is for the Rate this page section if (isset($_REQUEST[\'wsnum\'])) { $wsnum = $_REQUEST[\'wsnum\']; } // Check the cookie if(isset($_COOKIE[\'wsnumbc\'])) { $wsnum = $_COOKIE[\'wsnumbc\']; } else { setcookie(\'wsnumbc\', $wsnum); } // Global variable for calculated fields // Global variables should be defined here global $ww_custno; // retrieve the customer number parameter if (isset($_REQUEST[\'cmcust\'])) $ww_custno = $_REQUEST[\'cmcust\']; // Global variables should be defined here // As a default task for this program, execute the display function if ($pf_task == \'default\') display(); /******************** End of mainline code ********************/ function display() { // Make all global variables available here foreach($GLOBALS as $arraykey=>$arrayvalue) { global $$arraykey; } $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 "Error ".db2_stmt_error() .":".db2_stmt_errormsg(). ""; die; } if($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, OHCUST from XL_WEBDEMO/MU_ORDHL1 where OHCUST = $ww_custno"; // Fetch rows for page: relative to initial cursor if (!($stmt = db2_exec($db2conn, $query))) { echo "Error ".db2_stmt_error() .":".db2_stmt_errormsg(). ""; die; } wrtseg("ListHeader"); while ($row = db2_fetch_assoc($stmt)) { // set color of the line xl_set_row_color(\'altcol1\', \'altcol2\'); $OHCUST = $row["OHCUST"]; $OHORD = $row["OHORD"]; $OHDESC = $row["OHDESC"]; $OHORDT = $row["OHORDT"]; $OHSTAT = $row["OHSTAT"]; $OHOTOT = $row["OHOTOT"]; $OHORDT = strftime("%Y/%m/%d", strtotime($OHORDT)); wrtseg("ListDetails"); } // closet the database connection db2_close($db2conn); wrtseg("ListFooter"); } '; }