phpLens
 home  products examples manual  faq support forum  contact news  login store

More Examples:   Run: Subtotaling

Free Download

<?php
include('/big/dom/xphplens/www/php/phplens/phplens.inc.php');
session_start();
    
    
//----------------------------------------
    // The following lines are for formatting
    // the page and not needed by phplens
    
$gTitle = "Subtotaling";    
    include(
'./header.php');
    
    
//----------------------------------------------------
    // setup lens and render it with persistent connection
    
$lens = PHPLensPConnect (
        
'ex171',    // id to uniquely identify this phplens setup
        
"select * from products",
        
'mysql',     // database server type, eg. pgsql, odbc, mssql, oci8
        
$gEX_server,    // eg. localhost or ODBC DSN
        
$gEX_userid,    
        
$gEX_password,    
        
$gEX_db);    // optional, name of database to connect to
    
    
if ($lens) {
        
// SUBTOTAL BY STOCK
        
$lens->sumLens = 'UnitsInStock';
        
        
//------------------
        // GROUP BY CATEGORY
        
$lens->groupLens = 'categoryid';
        
        
$lens->pageSize = 20;
        
        
//-------------------------------------------------------------
        // map categoryid to categoryname and supplierid to companyname
        
$lens->lookupLens =
            
'CATEGORYID^select categoryid,categoryname from categories;'
            
.'SUPPLIERID^select supplierid,companyname from suppliers';
            
        
//----------------------------------
        // choose columns to display in grid
        
$lens->gridLens =
            
'PRODUCTNAME;SUPPLIERID;QUANTITYPERUNIT;UNITSINSTOCK;UNITPRICE';
            
        
//--------------------
        // shorten grid titles
        
$lens->nameLens =  
            
'CATEGORYID^Category;SUPPLIERID^Supplier;UNITSINSTOCK^Stock;'
            
.'UNITPRICE^Price;PRODUCTNAME^Product';
            
        
$lens->Render();
        
$lens->Close();
    }
?>
<h4>Notes</h4>

We set the <i>sumLens</i> property to get the totals and subtotals.

<?php        
include ('./footer.php');

?>



email: info#phplens.com (change # to @)     telephone (malaysia): 60-3 7806 1216     fax (malaysia): 60-3 7806 1210