Best Web Host

phpMyEdit example

MySQL™ table editor

Filename: phpvs_sakila.rental.php


Additional Fields
 Staff ID
 Last Update


 
Page: 1 of 1605  Records: 16044
Rental ID Rental Date Inventory ID Customer ID Return Date
Clear Sorted By: Rental ID ascending
View Change Copy Delete 1 2005-05-24 22:53:30 367 130 2005-05-26 22:04:30
View Change Copy Delete 2 2005-05-24 22:54:33 1525 459 2005-05-28 19:40:33
View Change Copy Delete 3 2005-05-24 23:03:39 1711 408 2005-06-01 22:12:39
View Change Copy Delete 4 2005-05-24 23:04:41 2452 333 2005-06-03 01:43:41
View Change Copy Delete 5 2005-05-24 23:05:21 2079 222 2005-06-02 04:33:21
View Change Copy Delete 6 2005-05-24 23:08:07 2792 549 2005-05-27 01:32:07
View Change Copy Delete 7 2005-05-24 23:11:53 3995 269 2005-05-29 20:34:53
View Change Copy Delete 8 2005-05-24 23:31:46 2346 239 2005-05-27 23:33:46
View Change Copy Delete 9 2005-05-25 00:00:40 2580 126 2005-05-28 00:22:40
View Change Copy Delete 10 2005-05-25 00:02:21 1824 399 2005-05-31 22:44:21
Page: 1 of 1605  Records: 16044

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: rental
 * Row count: 16044
 * Column count: 7
 * Filename: phpvs_sakila.rental.php
 * Created Wed, 22 Feb 2012 22:24:10 -0700
 * Primary key: rental_id
 * Null fields: return_date
 * Multi-key fields: rental_date, inventory_id, customer_id, staff_id
 * All fields: rental_id, rental_date, inventory_id, customer_id, return_date, staff_id,
last_update
*/

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

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

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

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

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

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


// column 1: `rental_date` datetime
// flags: binary, multiple_key, not_null
$opts['fdd']['rental_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'       => 'Rental Date',
  
'options'    => 'ACPVDFL',
  
'select'     => 'N',
  
'size'       => 19,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
$opts['fdd']['rental_date']['js']['required'] = true;
$opts['fdd']['rental_date']['js']['hint'] = 'An entry is required for Rental Date';


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


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


// column 4: `return_date` datetime
// flags: binary
$opts['fdd']['return_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'       => 'Return Date',
  
'options'    => 'ACPVDFL',
  
'select'     => 'N',
  
'size'       => 19,
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'sort'       => true
);
// $opts['fdd']['return_date']['js']['required'] = true;
// $opts['fdd']['return_date']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['return_date']['js']['hint'] = 'An entry is required for Return Date';


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


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