Best Web Host

phpMyEdit example

MySQL™ table editor

Filename: phpvs_sakila.film_list.php

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


Additional Fields
 Length
 Rating
 Actors


 
Page: 1 of 94  Records: 931
Fid Title Description Category Price
Clear Sorted By: Fid ascending
View 2 ACE GOLDFINGER A Astounding Epistle of a Database Administrato... Horror 4.99
View 3 ADAPTATION HOLES An Astounding Reflection of a Lumberjack And a ... Documentary 2.99
View 4 AFFAIR PREJUDICE A Fanciful Documentary of a Frisbee And a Lumbe... Horror 2.99
View 5 AFRICAN EGG A Fast-Paced Documentary of a Pastry Chef And a... Family 2.99
View 6 AGENT TRUMAN A Intrepid Panorama of a Robot And a Boy who mu... Foreign 2.99
View 7 AIRPLANE SIERRA A Touching Saga of a Hunter And a Butler who mu... Comedy 4.99
View 8 AIRPORT POLLOCK A Epic Tale of a Moose And a Girl who must Conf... Horror 4.99
View 9 ALABAMA DEVIL A Thoughtful Panorama of a Database Administrat... Horror 2.99
View 10 ALADDIN CALENDAR A Action-Packed Tale of a Man And a Lumberjack ... Sports 4.99
View 12 ALASKA PHANTOM A Fanciful Saga of a Hunter And a Pastry Chef w... Music 0.99
Page: 1 of 94  Records: 931

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: film_list
 * Row count: 931
 * Column count: 8
 * Filename: phpvs_sakila.film_list.php
 * Created Tue, 21 Feb 2012 12:36:25 -0700
 * Null fields: FID, title, description, price, length, rating, actors
 * All fields: FID, title, description, category, price, length, rating, actors
*/

$opts['tb'] = 'film_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('FID');

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

$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), 'Length'$z5);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$tmp6$z7), 'Rating'$z6);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$tmp7), 'Actors'$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: `FID` int - smallint(5) unsigned
// flags: unsigned
$opts['fdd']['FID'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'help|ACP'   => 'No auto_increment flag found.',
  
'input'      => '',
  
'maxlen'     => 5,
  
'name'       => 'Fid',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 5,
  
'sort'       => true
);
// If the tab feature is implemented, the first column must have a tab
// $opts['fdd']['FID']['tab|ACP'] = 'Fid';


// column 1: `title` string - varchar(255)
// collation: utf8_general_ci
$opts['fdd']['title'] = array(
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 255,
  
'name'       => 'Title',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 80,
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'sort'       => true
);


// column 2: `description` blob - text
// flags: blob
// collation: utf8_general_ci
$opts['fdd']['description'] = array(
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 21845,
  
'name'       => 'Description',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'strip_tags|FL' => true,
  
'textarea'   => array('rows' => 20'cols' => 80),
  
'trimlen|FL' => 50,
  
'sort'       => false
);


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


// column 4: `price` real - decimal(4,2)
$opts['fdd']['price'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 7,
  
'number_format|VDFL' => array(2'.'','),
  
'name'       => 'Price',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 7,
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'sort'       => true
);


// column 5: `length` int - smallint(5) unsigned
// flags: unsigned
$opts['fdd']['length'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 5,
//  'number_format|VDFL' => array(0, '.', ','),
  
'name'       => 'Length',
  
'options'    => $z5 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 5,
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'sort'       => true
);


// column 6: `rating` enum - enum('G','PG','PG-13','R','NC-17')
// flags: enum
// collation: utf8_general_ci
$opts['fdd']['rating'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 5,
  
'name'       => 'Rating',
  
'options'    => $z6 'ACPVDFL' 'ACPVD',
  
'select'     => 'D',
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'values'     => array('G','PG','PG-13','R','NC-17'), 
  
'sort'       => true
);


// column 7: `actors` string - varchar(341)
// collation: utf8_general_ci
$opts['fdd']['actors'] = array(
  
'default'    => '',
  
'input'      => '',
  
'maxlen'     => 341,
  
'name'       => 'Actors',
  
'options'    => $z7 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 80,
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'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.