Recently wanted to do a DataGrid function through PHP. This can directly modify the contents of the table in the database, without the development of "new data Page", "edit Page", so look for a search on the internet, similar things have a few, open source, paid to have, but the basic is based on MySQL. Because of the need to connect Oracle, from two development and page style, personally feel that Phpmydatagrid is still relatively good. This article first introduces the usage based on MySQL, and then briefly introduces two development for Oracle connection (based on Sqlrelay).
1. Create Test database and table
The following are the referenced contents:
Create database ' Guru ';
Use ' Guru ';
CREATE TABLE ' Employees ' (
' ID ' int (6) not NULL auto_increment,
' Name ' char ' default NULL,
' LastName ' char () default NULL,
' Salary ' float default NULL,
' Age ' int (2) default NULL,
' afiliation ' date default NULL,
' Status ' int (1) Default NULL,
' Active ' tinyint (1) Default NULL,
' Workeddays ' int (2) default NULL,
' Photo ' char () default NULL,
PRIMARY KEY (' id ')
)
INSERT INTO ' employees '
(' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
VALUES (1, ' Ana ', ' Trujillo ', 2000,45, ' 2005-05-13 ', 1,1,10, ' 1.jpg ');
INSERT INTO ' employees '
(' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
VALUES (2, ' Jennifer ', ' Aniston ', 3500,23, ' 2004-10-22 ', 1,0,0, ' 2.jpg ');
INSERT INTO ' employees '
(' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
VALUES (3, ' Michael ', ' Norman ', 1200,19, ' 2007-01-10 ', 1,1,5, ' 3.jpg ');
INSERT INTO ' employees '
(' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
VALUES (4, ' Vanessa ', ' black ', 6500,31, ' 2000-11-05 ', 1,1,30, ' 4.jpg ');
INSERT INTO ' employees '
(' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
VALUES (5, ' Michael ', ' Strauss ', 3200,45, ' 2006-10-21 ', 2,0,22, ' 5.jpg ');
INSERT INTO ' employees '
(' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
VALUES (6, ' William ', ' Brown ', 2300,21, ' 2001-03-10 ', 3,1,10, ' 6.jpg ');
INSERT INTO ' employees '
(' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
VALUES (7, ' Lucca ', ' Normany ', 2800,36, ' 2006-10-02 ', 3,1,20, ' 7.jpg ');
2. Introduction to PHP Program
Phpmydatagrid mainly through the phpmydatagrid.class.php,dgscripts.js to achieve, a total of less than 100kB, but also a small software. For these two documents is not much to say, interested students can "pack away" go back slowly product. This paper mainly introduces the use method of the software, i.e. instance datagrid_for_mysql.php. First look at the page diagram:
The following are the referenced contents:
<?php
Include ("phpmydatagrid.class.php");
$objGrid = new DataGrid;
$objGrid->closetags (TRUE);
$objGrid->friendlyhtml ();
$objGrid->methodform ("get");
Connecting to a database
$objGrid->conectadb ("127.0.0.1", "root", "root", "guru"); encrypted string
$objGrid->salt ("myc0defor5tr0ng3r-pro3ection");
$objGrid->language ("en");
The last column shows the function keys, from left to right function for "new key", "Edit Key", "Delete key", "Browse key".
$objGrid->buttons (true,true,true,true);
The form name that is produced when the value is modified
$objGrid->form (' employee ', true);
Can retrieve column names
$objGrid->searchby ("Name,lastname");
Tables that need to be read
$objGrid->tabla ("Employees");
Index values are used to modify data
$objGrid->keyfield ("id");
Page Show number of rows
$objGrid->datarows (20);
Default Sort method
$objGrid->orderby ("name", "ASC");
Display column settings, related settings can refer to phpmydatagrid.class.php
$objGrid->formatcolumn ("id", "ID Employee", 5, 5, 1, "M", "Center", "Integer");
$objGrid->formatcolumn ("name", "name", "0", "M", "left");
$objGrid->formatcolumn ("LastName", "Last Name", "0", "M", "left");
$objGrid->formatcolumn ("Age", "age", 5, 5, 0, "M", "right");//Custom date format
$objGrid->formatcolumn ("Afiliation", "Afiliation Date", ten, 0, "M", "center", "date:dmy:/");//edit can be customized as < select> mode
$objGrid ("Status", "status", 5, 5, 0, "->formatcolumn", "left", "select:1_single:2_married:3_divorced");
can be customized as <CheckBox> mode when editing
$objGrid->formatcolumn ("active", "active", 2, 2, 0, "M", "center", "Check:No:Yes");//Custom Currency display form
$objGrid->formatcolumn ("salary", "salary", ten, 0, "n", "right", "money:€"); To display the data as a bar chart
$objGrid->formatcolumn ("Workeddays", "Work Days", 5, 2, 0, "a", "right", "chart:percent:val:31");
$objGrid->checkable ();
$objGrid->setheader ();
$objGrid->ajax (' silent ');
Echo ' <body><div align= "center" ><br/> ';
Generate DataGrid
$objGrid->grid ();
Echo ' </div></body>$objGrid->desconectar ();
?>
3. Oracle Introduction
For Oracle reading is mainly to the phpmydatagrid.class.php of the function of the connection with MySQL to Oracle, this article is through the Sqlrelay (refer to http://sqlrelay.sourceforge.net/ Of course, you can also use PHP's self-contained OCI8 module (which is somewhat inefficient), and then save it as a phporadatagrid.class.php to be invoked in another program (datagrid_for_oracle.php). All of the programs mentioned above can be found in the compressed package.
Hope to be useful to everyone!