Location: PHPKode > scripts > MySQL Edit Table > example.php
<?php

/*

Table for this example.php:

--
-- Table structure for table 'employees'
--

CREATE TABLE employees (
  employeeNumber int(11) NOT NULL AUTO_INCREMENT,
  active enum('yes','no') NOT NULL,
  firstName varchar(50) NOT NULL,
  lastName varchar(50) NOT NULL,
  email varchar(100) NOT NULL,
  jobTitle enum('President','VP Sales','VP Marketing','Sales Manager','Sales Rep') NOT NULL,
  PRIMARY KEY (employeeNumber)
);

--
-- Dumping data for table 'employees'
--

INSERT INTO employees VALUES(1, 'yes', 'Diane', 'Murphy', 'hide@address.com', 'President');
INSERT INTO employees VALUES(2, 'no', 'Mary', 'Patterson', 'hide@address.com', 'VP Sales');
INSERT INTO employees VALUES(3, 'yes', 'Jeff', 'Firrelli', 'hide@address.com', 'VP Marketing');
INSERT INTO employees VALUES(4, 'no', 'William', 'Patterson', 'hide@address.com', 'Sales Manager');
INSERT INTO employees VALUES(5, 'no', 'Gerard', 'Bondur', 'hide@address.com', 'Sales Manager');
INSERT INTO employees VALUES(6, 'no', 'Anthony', 'Bow', 'hide@address.com', 'Sales Manager');
INSERT INTO employees VALUES(7, 'yes', 'Leslie', 'Jennings', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(8, 'yes', 'Leslie', 'Thompson', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(9, 'no', 'Julie', 'Firrelli', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(10, 'no', 'Steve', 'Patterson', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(11, 'yes', 'Foon Yue', 'Tseng', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(12, 'no', 'George', 'Vanauf', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(13, 'yes', 'Loui', 'Bondur', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(14, 'no', 'Gerard', 'Hernandez', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(15, 'yes', 'Pamela', 'Castillo', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(16, 'yes', 'Larry', 'Bott', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(17, 'no', 'Barry', 'Jones', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(18, 'yes', 'Andy', 'Fixter', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(19, 'no', 'Peter', 'Marsh', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(20, 'yes', 'Tom', 'King', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(21, 'no', 'Mami', 'Nishi', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(22, 'yes', 'Yoshimi', 'Kato', 'hide@address.com', 'Sales Rep');
INSERT INTO employees VALUES(23, 'no', 'Martin', 'Gerard', 'hide@address.com', 'Sales Rep');


*/


		#####################
		# required settings #
		#####################


session_start();
require_once("mte/mte.php");
$tabledit = new MySQLtabledit();

# database settings:
$tabledit->database = 'test';
$tabledit->host = 'localhost';
$tabledit->user = 'testname';
$tabledit->pass = 'testpass';

# table of the database
$tabledit->table = 'employees';

# the primary key of the table (must be AUTO_INCREMENT)
$tabledit->primary_key = 'employeeNumber';

# the fields you want to see in "list view"
$tabledit->fields_in_list_view = array('employeeNumber','active','firstName','lastName','email','jobTitle');



		#####################
		# optional settings #
		#####################


# language (en of nl)
$tabledit->language = 'en';

# numbers of rows/records in "list view"
$tabledit->num_rows_list_view = 10;

# required fields in edit or add record
$tabledit->fields_required = array('firstName','lastName');

# help text 
$tabledit->help_text = array(
	'employeeNumber' => "Don't edit this field",
	'active' => 'Active user, yes or no?',
	'firstName' => '',
	'lastName' => '',
	'email' => '',
	'jobTitle' => 'Please select!'
);

# visible name of the fields
$tabledit->show_text = array(
	'employeeNumber' => 'Number',
	'active' => 'Active',
	'firstName' => 'First name',
	'lastName' => 'Last name',
	'email' => 'Email',
	'jobTitle' => 'Job'
);

$tabledit->width_editor = '100%';
$tabledit->width_input_fields = '500px';
$tabledit->width_text_fields = '498px';
$tabledit->height_text_fields = '200px';

# warning no .htacces ('on' or 'off')
$tabledit->no_htaccess_warning = 'on';



		####################################
		# connect, show editor, disconnect #
		####################################


$tabledit->database_connect();

echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
	<html>
	<head>
	<title>MySQL table edit</title>
	</head>
	<body>
";

$tabledit->do_it();

echo "
	</body>
	</html>"
;

$tabledit->database_disconnect();
?>
Return current item: MySQL Edit Table