Best Web Host

phpMyEdit example

MySQL™ table editor

Filename: phpvs_sakila.staff_list.php

Data appearing below is compiled from a MySQL VIEW (a view is essentially a stored query; options restricted to VFL)


Additional Fields
 City
 Country
 Sid


 
Page: 1 of 1  Records: 2
ID Name Address Zip Code Phone
Clear Sorted By: ID ascending
View 1 Mike Hillyer 23 Workhaven Lane   14033335568
View 2 Jon Stephens 1411 Lillydale Drive   6172235589
Page: 1 of 1  Records: 2

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
 * View: staff_list
 * Row count: 2
 * Column count: 8
 * Filename: phpvs_sakila.staff_list.php
 * Created Wed, 22 Feb 2012 17:50:57 -0700
 * Null fields: zip code
 * All fields: ID, name, address, zip code, phone, city, country, SID
*/

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

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

// A VIEW is a stored SELECT query, not a MyISAM table.
// Un-editable. Need to do more research on how this might be made editable.
$opts['options'] = 'VFL'// ACPVDFL
echo "\n".'<p>Data appearing below is compiled from a MySQL VIEW (a view is essentially a stored query; options restricted to VFL)</p>';

// $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), 'City'$z5);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$tmp6$z7), 'Country'$z6);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$tmp7), 'Sid'$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

// No auto_increment field?

// column 0: `ID` int - tinyint(3) unsigned
// flags: not_null, unsigned
$opts['fdd']['ID'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => 0,
  
'help|ACP'   => 'No auto_increment flag found.',
  
'input'      => '',
  
'maxlen'     => 3,
  
'name'       => 'ID',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 3,
  
'sort'       => true
);
// If the tab feature is implemented, the first column must have a tab
// $opts['fdd']['ID']['tab|ACP'] = 'ID';


// column 1: `name` string - varchar(91)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['name'] = array(
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 91,
  
'name'       => 'Name',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 80,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);


// column 2: `address` string - varchar(50)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['address'] = array(
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 50,
  
'name'       => 'Address',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 50,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);


// column 3: `zip code` string - varchar(10)
// collation: utf8_general_ci
$opts['fdd']['zip code'] = array(
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 10,
  
'name'       => 'Zip Code',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 10,
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'sort'       => true
);


// column 4: `phone` string - varchar(20)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['phone'] = array(
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 20,
  
'name'       => 'Phone',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 20,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);


// column 5: `city` string - varchar(50)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['city'] = array(
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 50,
  
'name'       => 'City',
  
'options'    => $z5 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 50,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);


// column 6: `country` string - varchar(50)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['country'] = array(
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 50,
  
'name'       => 'Country',
  
'options'    => $z6 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 50,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);


// column 7: `SID` int - tinyint(3) unsigned
// flags: not_null, unsigned
$opts['fdd']['SID'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 3,
  
'name'       => 'Sid',
  
'options'    => $z7 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 3,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);

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.