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

More Examples:   Run: Advanced Filtering

Free Download

<?php
ob_start
();
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 "Advanced Filtering";
    include(
'./header.php');
?>
<p>
  This uses a filter template to reformat the search form vertically. The phpLens search
  form is very flexible. Try the following:
  <p>
  <table align=center cellpadding=2 border=1><tr><td>
- Search for all product id's greater than 30:  <td>  <b>>30</b> 
<tr><td>
- All product id's between 10 to 30: <td>  <b>10 (to) 30</b>
<tr><td>
- All product names beginning with V:  <td> <b>V</b>
</table>
  </ul>
  
</p>

<?php
$lens 
PHPLensPConnect('ex311',"select * from products order by 1",
        
'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) die('PHPLens ex311 failed to start');

$lens->firstState 'FILTERVIEW';
$lens->lookupLens 'CATEGORYID^select categoryid,categoryname from categories;SUPPLIERID^select supplierid,substring(companyname,1,20) from suppliers;QUANTITYPERUNIT^select distinct quantityperunit from products';

$lens->exportLens 'PRODUCTID;PRODUCTNAME;SUPPLIERID;CATEGORYID;QUANTITYPERUNIT';

$lens->colorNav '#c0c0c0';
$lens->colorNavBorder '#e0e0e0';
$lens->colorSelect 'yellow';

$lens->lang->topCaption '<b><font color=white> &nbsp; </font></b>';
$lens->lang->bottomCaption ' &nbsp;';
$lens->nameLens 'CATEGORYID^Category^^^^^;SUPPLIERID^Supplier^^^^^;QUANTITYPERUNIT^Qty/Unit^^^^^';

$lens->layoutTableHeader 'align="center" border="0" cellspacing="0" cellpadding="1" width="100%" ';
$lens->gridTableHeader 'width="100%" border="1" cellspacing="1" cellpadding="1" ';
$lens->detailTableHeader 'width="100%" border="1" cellspacing="0" cellpadding="2" ';

$lens->keyTable 'PRODUCTS';    // Save Data Table
$lens->keyCol 'PRODUCTID';    // Primary Key of Save Data Table
$lens->pageSize 50;    // rows per page
$lens->showRecNo 0;    // 0=hide 1=left 2=right
$lens->templateFilter 'ex311.tpl';

$lens->filterParams 'SUPPLIERID^^^2';


//-----------------
// Generate HTML

$lens->Render();
$lens->Close();

?>

<h3>Notes</h3>

This example demonstrates using a template to change the search screen:
<pre>
 $lens->templateFilter = 'ex311.tpl';
</pre>
<p>
The contents of the template:
<p>
<code>

{$<b>_FORMBEGIN_</b>}<br>
&lt;table width=&quot;100%&quot; border=&quot;1&quot;&gt;<br>
  &lt;tr bgcolor=&quot;#333333&quot;&gt;<br>
 &nbsp; &lt;td colspan=5 align=right&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;<br> {$<b>_SUBMIT_</b>}&lt;/font&gt;  {$<b>_DYNEDIT_</b>} &amp;nbsp; &lt;/td&gt;<br>
  &lt;/tr&gt;<br>
  &lt;tr bgcolor=&quot;#666666&quot;&gt;<br>
 &nbsp; &lt;td&gt;&lt;b&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;{$<b>PRODUCTID_T</b>}&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;<br>
 &nbsp; &lt;td&gt;&lt;b&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;{$<b>PRODUCTNAME_T</b>}    &lt;/font&gt;&lt;/b&gt;&lt;/td&gt;<br>
 &nbsp; &lt;td&gt;&lt;b&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;{$<b>SUPPLIERID_T</b>}&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;<br>
 &nbsp; &lt;td&gt;&lt;b&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;{$<b>CATEGORYID_T</b>}&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;<br>
 &nbsp; &lt;td&gt;&lt;b&gt;&lt;font color=&quot;#FFFFFF&quot;&gt;{$<b>QUANTITYPERUNIT_T</b>}&lt;/font&gt;&lt;/b&gt;&lt;/td&gt;<br>
  &lt;/tr&gt;<br>
  &lt;tr&gt;<br>
 &nbsp; &lt;td&gt;{$<b>PRODUCTID</b>}&lt;/td&gt;<br>
 &nbsp; &lt;td&gt;{$<b>PRODUCTNAME</b>}&lt;/td&gt;<br>
 &nbsp; &lt;td&gt;{$<b>SUPPLIERID</b>}&lt;/td&gt;<br>
 &nbsp; &lt;td&gt;{$<b>CATEGORYID</b>}&lt;/td&gt;<br>
 &nbsp; &lt;td&gt;{$<b>QUANTITYPERUNIT</b>}<br>
&lt;/td&gt;<br>
  &lt;/tr&gt;<br>
&lt;/table&gt;<br>
{$<b>_FORMEND_</b>}<br>
</p>
</code>
<p>
The template consists of the fields ,eg {$PRODUCTID}, and the captions {$PRODUCTID_T}. And we also 
have the buttons {$_SUBMIT_} and {$_CANCEL_}, though the cancel button has been removed. The
{$_DYNEDIT_} tag holds the green "e" editor button.
Finally we have the form management tags {$_FORMBEGIN_} and {$_FORMEND_}.
<p>
Other features include exporting to Excel [which requires the ob_start() call at the beginning of the page)] and setting the firstState to FILTERVIEW, so the search screen appears on startup.
<pre>
$lens->exportLens = 'PRODUCTID;PRODUCTNAME;SUPPLIERID;CATEGORYID;QUANTITYPERUNIT';
$lens->firstState = 'FILTERVIEW';
</pre>
<?php        
include ('./footer.php');
?>
email: contact#phplens.com (change # to @)     telephone (malaysia): 60-3-7947 2888     fax (malaysia): 60-3-7947 2800