Best Web Host

phpMyEdit example

MySQL™ table editor

Filename: phpvs_sakila.address.php


Additional Fields
 Postal Code
 Phone
 Last Update


 
Page: 1 of 61  Records: 604
Address ID Address Address2 District City ID
Clear Sorted By: Address ID ascending
View Change Copy Delete 1 47 MySakila Drive   Alberta 300
View Change Copy Delete 2 28 MySQL Boulevard   QLD 576
View Change Copy Delete 3 23 Workhaven Lane   Alberta 300
View Change Copy Delete 4 1411 Lillydale Drive   QLD 576
View Change Copy Delete 6 1121 Loja Avenue   California 449
View Change Copy Delete 7 692 Joliet Street   Attika 38
View Change Copy Delete 8 1566 Inegl Manor   Mandalay 349
View Change Copy Delete 9 53 Idfu Parkway   Nantou 361
View Change Copy Delete 10 1795 Santiago de Compostela Way   Texas 295
View Change Copy Delete 11 900 Santiago de Compostela Parkway   Central Serbia 280
Page: 1 of 61  Records: 604

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: address
 * Row count: 604
 * Column count: 8
 * Filename: phpvs_sakila.address.php
 * Created Wed, 22 Feb 2012 08:44:14 -0700
 * Primary key: address_id
 * Null fields: address2, postal_code
 * Multi-key fields: city_id
 * All fields: address_id, address, address2, district, city_id, postal_code, phone,
last_update
*/

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

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

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

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

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

   
// template used to apply the above values
   
$tpl '&z5=%s&z6=%s&z7=%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), 'Postal Code'$z5);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$tmp6$z7), 'Phone'$z6);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$tmp7), 'Last Update'$z7);
   
$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: `address_id` int - smallint(5) unsigned
// flags: auto_increment, not_null, primary_key, unsigned
// extra: auto_increment
$opts['fdd']['address_id'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'input'      => 'R',
  
'name'       => 'Address ID',
  
'options'    => 'VCDFL',
  
'select'     => 'T',
  
'size'       => 5,
  
'sort'       => true
);
// If the tab feature is implemented, the first column must have a tab
// $opts['fdd']['address_id']['tab|ACP'] = 'Address ID';


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


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


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


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


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


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


// column 7: `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'    => $z7 '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.