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
Orders
1 Music by the Numbers 7844 Franklin Blvd. Chicago US
Orders
2 Up Tempo Distributors 801 - 9558 Abbey Rd. Phoenix US
Orders
3 OER Music 301 10th Street NW Calgary CA
Orders
4 Maritime Music 3200 Capitol Blvd Olympia US
Orders
5 Swingin' Strings 2101 Louisiana Blvd NE Albuquerque US
Orders
6 Cam's Country 86 Bedford Street New York US
Orders
7 The Rock Studio 909 12th Street Sacramento US
Orders
8 The Welsh Connection 39302 Sunnyside Way Chicago US
Orders
9 Fruit of the Lute 7968 Vaughn Road Montgomery US
Orders
10 Phil's Philharmonic 5400 E Olympic Blvd Los Angeles US

Header Program:

  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 from XL_WEBDEMO.


  3. Choose the fields OHCUST, OHORD, OHDESC, OHORDT, OHSTAT and OHOTOT.


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

  5. 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';
    	
  6. 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");
    		
    		
    	}
    	
        
  7. Generate the program. To run it launch the "header" program that will pass the customer number as a parameter to the "details" program.

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.