Best Web Host

phpMyEdit example

MySQL™ table editor

Filename: phpvs_sakila.customer.php


Additional Fields
 Address ID
 Active
 Create Date
 Last Update


 
Page: 1 of 60  Records: 598
Customer ID Store ID First Name Last Name Email
Clear Sorted By: Customer ID ascending
View Change Copy Delete 2 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org
View Change Copy Delete 3 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org
View Change Copy Delete 4 2 BARBARA JONES BARBARA.JONES@sakilacustomer.org
View Change Copy Delete 5 1 ELIZABETH BROWN ELIZABETH.BROWN@sakilacustomer.org
View Change Copy Delete 6 2 JENNIFER DAVIS JENNIFER.DAVIS@sakilacustomer.org
View Change Copy Delete 7 1 MARIA MILLER MARIA.MILLER@sakilacustomer.org
View Change Copy Delete 8 2 SUSAN WILSON SUSAN.WILSON@sakilacustomer.org
View Change Copy Delete 9 2 MARGARET MOORE MARGARET.MOORE@sakilacustomer.org
View Change Copy Delete 10 1 DOROTHY TAYLOR DOROTHY.TAYLOR@sakilacustomer.org
View Change Copy Delete 11 2 LISA ANDERSON LISA.ANDERSON@sakilacustomer.org
Page: 1 of 60  Records: 598

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: customer
 * Row count: 598
 * Column count: 9
 * Filename: phpvs_sakila.customer.php
 * Created Wed, 22 Feb 2012 19:00:25 -0700
 * Primary key: customer_id
 * Null fields: email
 * Multi-key fields: store_id, last_name, address_id
 * All fields: customer_id, store_id, first_name, last_name, email, address_id, active,
create_date, last_update
*/

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

// 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('customer_id');

$opts['key'] = 'customer_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');

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

// 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);

   
// template used to apply the above values
   
$tpl '&z5=%s&z6=%s&z7=%s&z8=%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), 'Address ID'$z5);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$tmp6$z7$z8), 'Active'$z6);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$tmp7$z8), 'Create Date'$z7);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$z7$tmp8), 'Last Update'$z8);
   
$my_link_buffer .= "\n".'</p><br>';
}

// Buffered toggle links can be echo'ed in a container table TD left/right/below phpMyEdit form


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


// column 1: `store_id` int - tinyint(3) unsigned
// flags: multiple_key, not_null, unsigned
$opts['fdd']['store_id'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'help|ACP'   => 'Limit 3 digits',
  
'input'      => '',
  
'maxlen'     => 3,
  
'name'       => 'Store ID',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 3,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
$opts['fdd']['store_id']['js']['required'] = true;
$opts['fdd']['store_id']['js']['regexp'] = '/^[0-9]*$/';
$opts['fdd']['store_id']['js']['hint'] = 'An entry is required for Store ID';


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


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


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


// column 5: `address_id` int - smallint(5) unsigned
// flags: multiple_key, not_null, unsigned
$opts['fdd']['address_id'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'help|ACP'   => 'Limit 5 digits',
  
'input'      => '',
  
'maxlen'     => 5,
  
'name'       => 'Address ID',
  
'options'    => $z5 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 5,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['address_id']['js']['required'] = true;
// $opts['fdd']['address_id']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['address_id']['js']['hint'] = 'An entry is required for Address ID';


// column 6: `active` int - tinyint(1)
// flags: not_null
$opts['fdd']['active'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => 1,
  
'help|ACP'   => 'Limit 1 digits',
  
'input'      => '',
  
'maxlen'     => 1,
  
'name'       => 'Active',
  
'options'    => $z6 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 1,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['active']['js']['required'] = true;
// $opts['fdd']['active']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['active']['js']['hint'] = 'An entry is required for Active';


// column 7: `create_date` datetime
// flags: binary, not_null
$opts['fdd']['create_date'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => date('Y-m-d H:i:s'),
  
'help|ACP'   => 'YYYY-MM-DD HH:MM:SS',
  
'input'      => '',
  
'maxlen'     => 19,
  
'name'       => 'Create Date',
  
'options'    => $z7 'ACPVDFL' 'ACPVD',
  
'select'     => 'N',
  
'size'       => 19,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['create_date']['js']['required'] = true;
// $opts['fdd']['create_date']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['create_date']['js']['hint'] = 'An entry is required for Create Date';


// column 8: `last_update` timestamp
// flags: binary, not_null, timestamp, unsigned, zerofill
// extra: on update CURRENT_TIMESTAMP
$opts['fdd']['last_update'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'help|ACP'   => 'Timestamp',
  
'input'      => 'R',
  
'maxlen'     => 19,
  
'name'       => 'Last Update',
  
'options'    => $z8 'ACPVDFL' 'VD',
  
'select'     => 'N',
  
'size'       => 19,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['last_update']['js']['required'] = true;
// $opts['fdd']['last_update']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['last_update']['js']['hint'] = 'An entry is required for Last Update';

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

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.