Best Web Host

phpMyEdit example

MySQL™ table editor

Filename: phpvs_sakila.change_log.php


Additional Fields
 Tab
 Rowkey
 Col
 Oldval
 Newval
 Deleted


 
Page: 1 of 8  Records: 76
ID Updated User Host Operation
Clear Sorted By: ID ascending
View Change Copy Delete 1 2011-12-29 09:55:02   82.42.148.17 insert
View Change Copy Delete 2 2012-01-01 10:52:31   59.180.142.131 delete
View Change Copy Delete 3 2012-01-02 08:29:54   119.82.94.122 insert
View Change Copy Delete 4 2012-01-02 08:30:04   119.82.94.122 insert
View Change Copy Delete 5 2012-01-02 08:30:08   119.82.94.122 insert
View Change Copy Delete 6 2012-01-04 01:54:53   217.122.100.65 update
View Change Copy Delete 7 2012-01-04 01:55:05   217.122.100.65 update
View Change Copy Delete 8 2012-01-04 05:06:26   109.162.179.126 insert
View Change Copy Delete 9 2012-01-04 05:06:33   109.162.179.126 delete
View Change Copy Delete 10 2012-01-04 06:40:00   193.136.111.124 update
Page: 1 of 8  Records: 76

Tables containing more than 'n' columns are configured to display the first 'n' columns and display links to toggle (add/remove) the remaining columns.

Users are advised to use phpMyAdmin to set an INDEX for columns which are often sorted/searched. Most web hosts provide phpMyAdmin in the website control panel.

Try Hostgator.com for excellent web hosting with cPanel, PHP, MySQL™ and many other features. cPanel PHP MySQL web hosting


phpMyEdit code created for the above table.

<?php

/*
 * Database: phpvs_sakila
 * Table: change_log
 * Row count: 76
 * Column count: 11
 * Filename: phpvs_sakila.change_log.php
 * Created Wed, 22 Feb 2012 22:48:19 -0700
 * Primary key: id
 * Null fields: oldval, newval
 * Multi-key fields: tab, col
 * All fields: id, updated, user, host, operation, tab, rowkey, col, oldval, newval, deleted
*/

$opts['tb'] = 'change_log';

// $opts['logtable'] is suppressed (not to be used with itself)

// phpMyEdit common variables + a few functions + UTF8 database connection

require_once('./resources/inc/config.php');

require_once(
'./resources/inc/header.php');

// Use phpMyAdmin to apply an INDEX to columns which are frequently sorted/searched.
// Prepending a minus sign (-) to a sort_field value causes DESCending sort order.

$opts['sort_field'] = array('id');

$opts['key'] = 'id';

$opts['key_type'] = 'int';

$opts['options'] = 'ACPVDFL';

// $opts['triggers']['insert']['after'] = 'resources/inc/triggers/view_rec_after_add.php';

if(empty($list_mode_status)){
   
// List mode
}elseif(isset($_REQUEST['PME_sys_operation']) || isset($_REQUEST['PME_sys_moreadd']) && isset($_REQUEST['PME_sys_morechange'])){
   
// 7 diffenent button clicks may occur
   // PME_sys_operation: Add, PME_op_Change, PME_op_Copy, PME_op_Delete, PME_op_View
   // PME_sys_moreadd: More
   // PME_sys_morechange: Apply
}


// Initialize toggle variables based on column number
$z5 get_cgi_var('z5');
$z6 get_cgi_var('z6');
$z7 get_cgi_var('z7');
$z8 get_cgi_var('z8');
$z9 get_cgi_var('z9');
$z10 get_cgi_var('z10');

// Toggle variables need to be persistent
$opts['cgi']['persist'] = array(
'z5' => $z5'z6' => $z6'z7' => $z7'z8' => $z8'z9' => $z9'z10' => $z10);

// Buffer the toggling links in order to facilitate their display
// above/below the form, or left/right the phpMyEdit form in TD tags
$my_link_buffer '';

if(
$list_mode_status){
   
$bqs ''// buffered query string (phpMyEdit system variables)
   
$ignore_keys = array(
      
'PME_sys_canceladd',
      
'PME_sys_cancelcopy',
      
'PME_sys_canceldelete',
      
'PME_sys_cancelview',
      
'PME_sys_cur_tab',
      
'PME_sys_moreadd',
      
'PME_sys_qfn',
      
'PME_sys_savechange'
   
);
   foreach(
$_REQUEST as $key => $val){
      if(
substr($key08) == 'PME_sys_' && !in_array($key$ignore_keys)){
         if(
is_array($val)){
            foreach(
$val as $k => $v){
               
$bqs .= '&'.$k.'='.$v;
            }
         }else{
            
$bqs .= '&'.$key.'='.$val;
         }
      }
   }
    
   
// calculate opposite values beginning with MySQL column #5
   
$tmp5 '&z5='.(empty($z5) ? 0);
   
$tmp6 '&z6='.(empty($z6) ? 0);
   
$tmp7 '&z7='.(empty($z7) ? 0);
   
$tmp8 '&z8='.(empty($z8) ? 0);
   
$tmp9 '&z9='.(empty($z9) ? 0);
   
$tmp10 '&z10='.(empty($z10) ? 0);

   
// template used to apply the above values
   
$tpl '&z5=%s&z6=%s&z7=%s&z8=%s&z9=%s&z10=%s';

    
// Note the progressive shift from one column to the next
   
$my_link_buffer .= "\n".'<p><hr>Additional Fields<hr>';
   
$my_link_buffer .= htmlLink(sprintf($tpl$tmp5$z6$z7$z8$z9$z10), 'Tab'$z5);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$tmp6$z7$z8$z9$z10), 'Rowkey'$z6);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$tmp7$z8$z9$z10), 'Col'$z7);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$z7$tmp8$z9$z10), 'Oldval'$z8);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$z7$z8$tmp9$z10), 'Newval'$z9);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$z7$z8$z9$tmp10), 'Deleted'$z10);
   
$my_link_buffer .= "\n".'</p><br>';
}

// Buffered toggle links can be echo'ed in a container table TD left/right/below phpMyEdit form
if(empty($z10)){ $opts['filters'] = 'PMEtable0.deleted = "0"'; }

$opts['triggers']['delete']['before'] = 'inc/triggers/mark_as_deleted.TDB.inc';


echo 
"\n".'<table border="0" cellpadding="0" cellspacing="0">';

echo 
"\n".'<tr valign="top">';

if(!empty(
$my_link_buffer)){
   echo 
"\n".'<td style="white-space:nowrap;background-color:#f0f8ff;padding:10px;border:1px solid #cccccc">'."\n";
   echo 
$my_link_buffer;
   echo 
"\n".'</td>';
   echo 
"\n".'<td width="15">&nbsp;</td>'// spacer
}

echo 
"\n".'<td>'."\n"// container for phpMyEdit form

// Begin phpMyEdit field arrays

// column 0: `id` int - mediumint(6) unsigned
// flags: auto_increment, not_null, primary_key, unsigned
// extra: auto_increment
$opts['fdd']['id'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'input'      => 'R',
  
'name'       => 'ID',
  
'options'    => 'VCDFL',
  
'select'     => 'T',
  
'size'       => 6,
  
'sort'       => true
);
// If the tab feature is implemented, the first column must have a tab
// $opts['fdd']['id']['tab|ACP'] = 'ID';


// column 1: `updated` timestamp
// flags: binary, not_null, timestamp, unsigned, zerofill
// extra: on update CURRENT_TIMESTAMP
$opts['fdd']['updated'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'help|ACP'   => 'Timestamp',
  
'input'      => 'R',
  
'maxlen'     => 19,
  
'name'       => 'Updated',
  
'options'    => 'VDFL',
  
'select'     => 'N',
  
'size'       => 19,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
$opts['fdd']['updated']['js']['required'] = true;
$opts['fdd']['updated']['js']['hint'] = 'An entry is required for Updated';


// column 2: `user` string - varchar(50)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['user'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 50 characters',
  
'input'      => '',
  
'maxlen'     => 50,
  
'name'       => 'User',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 50,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
$opts['fdd']['user']['js']['required'] = true;
$opts['fdd']['user']['js']['hint'] = 'An entry is required for User';


// column 3: `host` string - varchar(255)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['host'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 255 characters',
  
'input'      => '',
  
'maxlen'     => 255,
  
'name'       => 'Host',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 80,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
$opts['fdd']['host']['js']['required'] = true;
$opts['fdd']['host']['js']['hint'] = 'An entry is required for Host';


// column 4: `operation` string - varchar(50)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['operation'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 50 characters',
  
'input'      => '',
  
'maxlen'     => 50,
  
'name'       => 'Operation',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 50,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['operation']['js']['required'] = true;
// $opts['fdd']['operation']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['operation']['js']['hint'] = 'An entry is required for Operation';


// column 5: `tab` string - varchar(50)
// flags: multiple_key, not_null
// collation: utf8_general_ci
$opts['fdd']['tab'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 50 characters',
  
'input'      => '',
  
'maxlen'     => 50,
  
'name'       => 'Tab',
  
'options'    => $z5 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 50,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['tab']['js']['required'] = true;
// $opts['fdd']['tab']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['tab']['js']['hint'] = 'An entry is required for Tab';


// column 6: `rowkey` string - varchar(255)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['rowkey'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 255 characters',
  
'input'      => '',
  
'maxlen'     => 255,
  
'name'       => 'Rowkey',
  
'options'    => $z6 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 80,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['rowkey']['js']['required'] = true;
// $opts['fdd']['rowkey']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['rowkey']['js']['hint'] = 'An entry is required for Rowkey';


// column 7: `col` string - varchar(255)
// flags: multiple_key, not_null
// collation: utf8_general_ci
$opts['fdd']['col'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 255 characters',
  
'input'      => '',
  
'maxlen'     => 255,
  
'name'       => 'Col',
  
'options'    => $z7 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 80,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['col']['js']['required'] = true;
// $opts['fdd']['col']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['col']['js']['hint'] = 'An entry is required for Col';


// column 8: `oldval` blob - text
// flags: blob
// collation: utf8_general_ci
$opts['fdd']['oldval'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 65,535 characters',
  
'input'      => '',
  
'maxlen'     => 65535,
  
'name'       => 'Oldval',
  
'options'    => $z8 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'strip_tags|FL' => true,
  
'textarea'   => array('rows' => 20'cols' => 80),
  
'trimlen|FL' => 50,
  
'sort'       => false
);
// $opts['fdd']['oldval']['js']['required'] = true;
// $opts['fdd']['oldval']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['oldval']['js']['hint'] = 'An entry is required for Oldval';


// column 9: `newval` blob - text
// flags: blob
// collation: utf8_general_ci
$opts['fdd']['newval'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 65,535 characters',
  
'input'      => '',
  
'maxlen'     => 65535,
  
'name'       => 'Newval',
  
'options'    => $z9 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'strip_tags|FL' => true,
  
'textarea'   => array('rows' => 20'cols' => 80),
  
'trimlen|FL' => 50,
  
'sort'       => false
);
// $opts['fdd']['newval']['js']['required'] = true;
// $opts['fdd']['newval']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['newval']['js']['hint'] = 'An entry is required for Newval';


// column 10: `deleted` int - tinyint(1) unsigned
// flags: not_null, unsigned
$opts['fdd']['deleted'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => 0,
  
'help|ACP'   => 'Limit 1 digits',
  
'input'      => '',
  
'maxlen'     => 1,
  
'name'       => 'Deleted',
  
'options'    => $z10 'ACPVDFL' '',
  
'select'     => 'T',
  
'size'       => 1,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);

require_once(
'./resources/inc/phpMyEdit.class.new.php');

if(
array_key_exists('PME_sys_moreadd'$_REQUEST) || (isset($_REQUEST['PME_sys_operation']) && $_REQUEST['PME_sys_operation'] == 'Add')){ $opts['cgi']['overwrite']['deleted'] = '0'; }

new 
phpMyEdit($opts);

echo 
"\n".'</td>'// close the phpMyEdit form

echo "\n".'</tr>';

echo 
"\n".'</table>';

require_once(
'./resources/inc/footer.php');

?>


cPanel PHP MySQL web hosting

If you have pre-purchase questions, please call Doug Hockinson at (720) 334-7850 or send email to doug@hockinson.com.

Data used for this demo is a modified version of Sakila schema (converted to MyISAM type tables)

Related sites: php-form-generator.com | phpvs.com | hockinson.com | denvermetro.org

Content management system with built in photo galleries and phpMyEdit form generator: www.phpvs.com/cms2011/

Regarding the style sheet used by these scripts, un-comment some CSS code for body and wrapper in order to match the layout of the generator script.

In page modes Add, Change, and coPy, note the Help text displayed beside the fields. Several configurable options are available: character limit, link to Help popup, code supplied but commented out (no value), display "Entry Required", or MySQL Column Comment.