Misc. examples, including filter examples for phpMyEdit-based forms.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
When filtering records *and* doing lookups to another table
where *both* tables contain a column of the same name, you will
likely need to call your filter as:
$opts['filters'] = 'PMEtable0.deleted = "N"';
and *not* simply:
$opts['filters'] = 'deleted = "N"';
$opts['fdd']['owner_id'] = array(
'css' => array('postfix' => 'right-justify'),
'default' => '0',
'input' => '',
'maxlen' => 5,
'name' => 'Site Owner',
'options' => 'ACPVD',
'required' => false,
'select' => 'T',
'size|ACP' => 5,
'sqlw' => 'TRIM("$val_as")',
'sort' => true,
'values' => array(
'table' => 'contacts',
'column' => 'contact_id',
'description' => array(
'columns' => array('display_name', 'company', 'last_name'),
'divs' => array(' ', ' ', ' ')
),
'filters' => 'category = "Client"'
)
);
// MySQL column 30: int - smallint(5) unsigned
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Note: 'filters' is used for filtering items in dropdown during ADD/CHANGE mode using with a SQL WHERE. And ['join'] is useful for having a correct LEFT JOIN against the main table in LIST/VIEW mode.
$opts['fdd']['vendor']['values']['join'] =
'PMEjoin6.part_no = PMEtable0.part_no AND is_preferred = "TRUE" ';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Force the Search feature ON:
$opts['cgi']['append']['PME_sys_fl'] = 1; // Version 5.0+
$opts['cgi']['append']['fl'] = 1; // older phpMyEdit versions
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
See filters2.txt for example of filtering
for the first letter of a Company or Last Name.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Disable all filters
$opts['cgi']['overwrite']['fl'] = 0;
// Prevent the sort order from being altered by column title links
$opts['cgi']['overwrite']['PME_sys_sfn'] = '-0';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$opts['filters'] = 'PMEjoin1.FullName NOT LIKE "%..%"';
$opts['filters'] = 'PMEtable0.FullName NOT LIKE "%--Select--%"';
$opts['filters'] = 'PMEtable0.FullName NOT LIKE "%..%"';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Variables used in most filters can be passed from another form, or from a link included in the page footer.
A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
In the requested form, process the variable and make it persistent across various page modes (Next, Previous, Search, Cancel).
$ltr = array_key_exists('ltr', @$_REQUEST) ? strip_tags(stripslashes(trim(@$_REQUEST['ltr']))) : '';
$opts['cgi']['persist'] = array('ltr' => $ltr);
--- OR ---
$ltr = @$_GET['ltr'];
if(!isset($ltr)) {
$ltr = @$_POST['ltr'];
}
$opts['cgi']['persist'] = array('ltr' => $ltr);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Filter records based on a letter passed to the form and make it persistent.
$ltr = array_key_exists('ltr', @$_REQUEST) ? strip_tags(stripslashes(trim(@$_REQUEST['ltr']))) : '';
$opts['filters'] = 'company REGEXP "^'.$ltr.'"';
$opts['cgi']['persist'] = array('ltr' => $ltr );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
A sessions script passes $_SESSION['valid_user'] AND a column named valid_user also exists
in rows of records accessible only to $_SESSION['valid_user'] and fictitious user 'public'.
$opts['filters'] = 'valid_user = "'.$_SESSION['valid_user'].'" OR valid_user = "public"';
$opts['cgi']['persist'] = array('valid_user' => $_SESSION['valid_user'] );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The following configures a persistent table level filter for one record.
Record remains filtered even if user clicks Cancel to leave View mode.
$id = array_key_exists('id', @$_GET) ? @$_GET['id'] : $rec;
$opts['cgi']['persist'] = array('id' => $col_name);
$opts['filters'] = $id > 0 ? "col_name = '$id'" : '';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
* fl2 is an acronym for filter #2 since
* fl is the name of phpMyEdit's default filter.
*
* Usage = links in form footer:
All Records |
1 |
2 |
3
*/
$fl2 = array_key_exists('fl2', @$_REQUEST) ? strip_tags(stripslashes(trim(@$_REQUEST['fl2']))) : '';
if($fl2 > 0) {
$opts['cgi']['persist'] = array('fl2' => $fl2);
}
switch($fl2)
{
Case 1:
$opts['filters'] = ''; // enter valid SQL
break;
Case 2:
$opts['filters'] = ''; // enter valid SQL
break;
Case 3:
$opts['filters'] = ''; // enter valid SQL
break;
Case 0:
default:
break;
}
// $oper_label .= isset($fl2) && $fl2 == 'user' ? ' Authorized Users' : ' All Hits';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// sfn is a sort function in phpMyEdit.class.php
// name the user sort function sfn2
$sfn2 = array_key_exists('sfn2', @$_REQUEST) ? strip_tags(stripslashes(trim(@$_REQUEST['sfn2']))) : '';
$opts['cgi']['persist'] = array('sfn2' => $sfn2);
switch($sfn2)
{
Case 1:
$opts['sort_field'] = array('-id'); // descending
break;
Case 0: // fall through to default
default:
$opts['sort_field'] = array('id'); // ascending
break;
}
Links in footer:
Ascending ID
-
Descending ID
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// See also filters2.txt
// $lnltr = first letter of LastName passed (page.php?lnltr=A)
// $bzltr = first letter of Company passed (page.php?bzltr=A)
if(empty($operation) && empty($morechange)) {
if(!isset($lnltr)) {
$lnltr = array_key_exists('lnltr', @$_GET) ? @$_GET['lnltr'] : '' ;
}elseif(!isset($bzltr)) {
$bzltr = array_key_exists('bzltr', @$_GET) ? @$_GET['bzltr'] : '' ;
}
if(!empty($lnltr)) {
// Filter Agent ID and letter
$opts['filters'] = 'RecordOwnerID = "'.$AgentID.'" AND PMEtable0.LastName REGEXP "^'.$lnltr.'"';
$opts['cgi']['persist'] = array('lnltr' => $lnltr );
$opts['sort_field'] = array('LastName', 'FirstName', 'Company');
$notice = 'LastName filter = '.$lnltr;
}elseif(!empty($bzltr)) {
// Filter Agent ID and letter
$opts['filters'] = 'RecordOwnerID = "'.$AgentID.'" AND PMEtable0.Company REGEXP "^'.$bzltr.'"';
$opts['cgi']['persist'] = array('bzltr' => $bzltr );
$opts['sort_field'] = array('Company', 'LastName', 'FirstName');
$notice = 'Company filter = '.$bzltr;
}else{
// Filter Agent ID only
$opts['filters'] = 'RecordOwnerID = "'.$AgentID.'"';
$opts['sort_field'] = array('LastName', 'Company');
$notice = '';
}
}else{
$oper_label = $operation;
}
// Page footer:
| ">Remove Filter | '.$notice.''; ?> |
| Last Name Filter: |
'.chr($i).'';
echo ($i < 90) ? ' - '."\n" : "\n";
}
?>
|
| Company Filter: |
'.chr($i).'';
echo ($i < 90) ? ' - '."\n" : "\n";
}
?>
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$fl2 = array_key_exists('fl2', @$_REQUEST) ? strip_tags(stripslashes(trim(@$_REQUEST['fl2']))) : '';
if($fl2 > 0) { $opts['cgi']['persist'] = array('fl2' => $fl2); }
$oper_label = empty($operation) ? 'List' : $operation;
switch($fl2) {
Case 1:
$opts['filters'] = 'SourceFlag = "MDD2" AND MLS2_SN <> ".."';
$opts['sort_field'] = array('MLS4_ST', 'MLS2_SN', 'MLS3_STRD');
$oper_label = 'List MDD2';
break;
Case 2:
$opts['filters'] = 'SourceFlag = "MDD2-REC" AND MLS2_SN <> ".."';
$opts['sort_field'] = array('MLS4_ST', 'MLS2_SN', 'MLS3_STRD');
$oper_label = 'List MDD2-REC';
break;
Case 3:
$opts['filters'] = 'SourceFlag = "AFS" AND MLS2_SN <> ".."';
$opts['sort_field'] = array('MLS4_ST', 'MLS2_SN', 'MLS3_STRD');
$oper_label = 'List AFS';
break;
Case 4:
$opts['filters'] = 'SourceFlag = "ACTIVE" AND MLS2_SN <> ".."';
$opts['sort_field'] = array('MLS4_ST', 'MLS2_SN', 'MLS3_STRD');
$oper_label = 'List Active';
break;
Case 5:
$opts['filters'] = 'SourceFlag = "PENDING" AND MLS2_SN <> ".."';
$opts['sort_field'] = array('MLS4_ST', 'MLS2_SN', 'MLS3_STRD');
$oper_label = 'List Pending';
break;
Case 6:
$opts['filters'] = 'SourceFlag = "MDD2-REC" OR SourceFlag = "MDD2" AND MLS2_SN <> ".."';
$opts['sort_field'] = array('MLS4_ST', 'MLS2_SN', 'MLS3_STRD');
$oper_label = 'List MDD2 and MDD2-REC';
break;
Case 0: // fall thru (ALL records)
default:
$opts['sort_field'] = array('MLSNum');
$oper_label = 'List All by MLSNum';
break;
}
// Page footer:
echo "\n".'| Filters: | '."\n";
echo ($fl2 != 0) ? 'ALL (select before using Search feature below) | ' : 'ALL records selected | ';
echo ($fl2 != 1) ? 'MDD2 | ' : 'MDD2 | ';
echo ($fl2 != 2) ? 'MDD2-REC | ' : 'MDD2-REC | ';
echo ($fl2 != 6) ? 'MDD2 and MDD2-REC | ' : 'MDD2 and MDD2-REC | ';
echo ($fl2 != 3) ? 'AFS | ' : 'AFS | ';
echo ($fl2 != 4) ? 'ACTIVE | ' : 'ACTIVE | ';
echo ($fl2 != 5) ? 'PENDING | ' : 'PENDING | ';
echo "\n".'
'."\n";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Example: a minus sign (-) in front of a column name enforces descending sort order.
$opts['sort_field'] = array('-date_field', '-time_field');
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// RecordOwnerID - smallint(5) unsigned - int
$opts['fdd']['RecordOwnerID'] = array(
'name' => 'Record Owner ID',
'select' => 'D',
'options' => 'ACPVD',
'maxlen' => 5,
'default' => '0',
'required' => false,
'sort' => true
);
$opts['fdd']['RecordOwnerID']['values']['table'] = 'mdd_staff'; // other table
$opts['fdd']['RecordOwnerID']['values']['column'] = 'AgentID'; // column e.g. id
$opts['fdd']['RecordOwnerID']['values']['description']['columns']['0'] = 'FullName';
$opts['fdd']['RecordOwnerID']['values']['filters'] = 'AgentID = "'.$AgentID.'"';
$opts['cgi']['overwrite']['RecordOwnerID'] = $AgentID;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// LastModByID - smallint(5) unsigned - int
$opts['fdd']['LastModByID'] = array(
'name' => 'Last Mod By ID',
'select' => 'D',
'options' => 'ACPVD',
'maxlen' => 5,
'default' => '0',
'required' => false,
'sort' => true
);
$opts['fdd']['LastModByID']['values']['table'] = 'mdd_staff'; // other table
$opts['fdd']['LastModByID']['values']['column'] = 'AgentID'; // column e.g. id
$opts['fdd']['LastModByID']['values']['description']['columns']['0'] = 'FullName';
$opts['fdd']['LastModByID']['values']['filters'] = 'AgentID = "'.$AgentID.'"';
$opts['cgi']['overwrite']['LastModByID'] = $AgentID;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// FILTER ONLY FOR COMPANY RECORDS AgentID = 86
if(empty($operation) && empty($morechange)) {
if(!isset($lnltr)) {
$lnltr = array_key_exists('lnltr', @$_GET) ? @$_GET['lnltr'] : '' ;
}elseif(!isset($bzltr)) {
$bzltr = array_key_exists('bzltr', @$_GET) ? @$_GET['bzltr'] : '' ;
}
if(!empty($lnltr)) {
// Filter MDD (86)
$opts['filters'] = 'RecordOwnerID = "86" AND PMEtable0.LastName REGEXP "^'.$lnltr.'"';
$opts['cgi']['persist'] = array('lnltr' => $lnltr );
$opts['sort_field'] = array('LastName', 'FirstName', 'Company');
$notice = 'LastName filter = '.$lnltr;
}elseif(!empty($bzltr)) {
$opts['filters'] = 'RecordOwnerID = "86" AND PMEtable0.Company REGEXP "^'.$bzltr.'" OR RecordOwnerID = "86" AND PMEtable0.Company REGEXP "^'.$bzltr.'"';
$opts['cgi']['persist'] = array('bzltr' => $bzltr );
$opts['sort_field'] = array('Company', 'LastName', 'FirstName');
$notice = 'Company filter = '.$bzltr;
}else{
$opts['sort_field'] = array('LastName', 'Company');
$opts['filters'] = 'RecordOwnerID = "86"';
$notice = '';
}
}else{
$oper_label = $operation;
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$opts['filters'] = 'Category <> ".."';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$opts['filters'] = 'MessageFor = "'.$AgentID.'" AND PMEtable0.Status <> 1';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$opts['filters'] = 'PMEtable0.AgentID = "'.$AgentID.'"';
$opts['cgi']['persist'] = array('AgentID' => $AgentID);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$grouping = array_key_exists('grouping', @$_REQUEST) ? strip_tags(stripslashes(trim(@$_REQUEST['grouping']))) : '';
$opts['cgi']['persist'] = array('grouping' => $grouping);
if($grouping) {
$opts['sort_field'] = array('System', 'AgentID');
$oper_label = empty($operation) ? 'Click column titles to sort records' : $operation;
}else{
$opts['filters'] = 'PMEjoin1.FullName NOT LIKE "%..%"';
$opts['sort_field'] = array('AgentID');
$oper_label = empty($operation) ? 'Telephone DID Configuration' : $operation;
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// AgentID - mediumint(8) - int
$opts['fdd']['AgentID'] = array(
'name' => 'Agent',
'select' => 'D',
'maxlen' => 8,
'default' => '0',
'required' => true,
'sort' => true
);
$opts['fdd']['AgentID']['help|ACP'] = 'Select';
$opts['fdd']['AgentID']['values']['table'] = 'mdd_staff'; // other table
$opts['fdd']['AgentID']['values']['column'] = 'AgentID'; // column e.g. id
$opts['fdd']['AgentID']['values']['description']['columns']['0'] = 'FullName';
$opts['fdd']['AgentID']['values']['filters'] = 'Status = 1';
$opts['fdd']['AgentID']['nowrap'] = true;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Address - mediumint(8) - int
$opts['fdd']['Address'] = array(
'name' => 'Address',
'select' => 'D',
'maxlen' => 8,
'default' => '0',
'required' => false,
'sort' => true
);
$opts['fdd']['Address']['values']['table'] = 'all_data';
$opts['fdd']['Address']['values']['column'] = 'HouseID';
$opts['fdd']['Address']['values']['description']['columns']['0'] = 'Street';
$opts['fdd']['Address']['values']['description']['divs']['0'] = ' ';
$opts['fdd']['Address']['values']['description']['columns']['1'] = 'StNo';
$opts['fdd']['Address']['values']['description']['divs']['1'] = ' ';
$opts['fdd']['Address']['values']['description']['columns']['2'] = 'StDir';
$opts['fdd']['Address']['values']['description']['divs']['2'] = ' ';
$opts['fdd']['Address']['values']['description']['columns']['3'] = 'Unit';
$opts['fdd']['Address']['values']['filters'] = 'Street > "" AND Status = "1" OR Status = "3" ';
$opts['fdd']['Address']['values']['orderby'] = 'Street';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Possible setting: $opts['sort_field'] = array('id');
// Replace with:
$order = array_key_exists('order', @$_REQUEST) ? strip_tags(stripslashes(trim(@$_REQUEST['order']))) : '';
$opts['cgi']['persist'] = array('order' => $order);
$opts['sort_field'] = empty($order) ? array('id') : array(-'id');
First Record
Last Record
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sorting Examples:
// This will cause descending sorting according first field
// if other type of sort was not specified/selected by user.
$opts['cgi']['append'] = array('sfn' => '-0');
// This will cause the same sort allways in all cases.
$opts['cgi']['overwrite'] = array('sfn' => '-0');
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Near top of form:
/**
* fl2 is an acronym for filter #2 since
* fl is the name of phpMyEdit's default filter.
*
* Usage = links in form footer:
* 1
* 2
* 3
*/
$fl2 = array_key_exists('fl2', @$_REQUEST) ? strip_tags(stripslashes(trim(@$_REQUEST['fl2']))) : '';
if($fl2 > 0) {
$opts['cgi']['persist'] = array('fl2' => $fl2);
$opts['filters'] = "col_name='$fl2'"; // enter valid SQL
}
Near bottom of form:
if(empty($operation)){
if($res = @mysql_query("SELECT col_name, link FROM ".$opts['tb']." WHERE pnum = '0' ORDER BY col_name") or die('Query failed [#1]. '.mysql_errno().': '.mysql_error().'