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

More Examples:   Run: Group by Category

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 "Group by Category";    
    include(
'./header.php');
    
    
//----------------------------------------------------
    // setup lens and render it with persistent connection
    
$lens PHPLensPConnect (
        
'ex170',    // 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) {
        
//------------------
        // 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>groupLens</i> property here to group by CategoryID.

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

?>



email: contact#phplens.com (change # to @)     telephone (malaysia): 60-3-7947 2888     fax (malaysia): 60-3-7947 2800