Recently want to do a function of the DataGrid through PHP, so that you can directly modify the contents of the table in the database, without the development of "new data Page", "edit Page", and so on the Internet to find, similar things also have a few, open source, paid to have, but basically is based on MySQL. Because of the need to connect to Oracle so from two times development and page style personally feel phpmydatagrid is better to get started. This article begins with a MySQL-based approach, and briefly introduces two development for Oracle connectivity (based on Sqlrelay).
1. Creating a test database and tables
- Create database ' Guru ';
- Use ' Guru ';
- CREATE TABLE ' Employees ' (
- ' ID ' int (6) not NULL auto_increment,
- ' name ' char (a) 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 Programs
Phpmydatagrid mainly through the phpmydatagrid.class.php,dgscripts.js to achieve, in total add up to 100kB, is a small software. For these two files are not much to say, interested students can "pack away" back to slowly product. This paper mainly introduces the use method of the software, i.e. instance datagrid_for_mysql.php. First look at the page:
498) this.width=498; ' OnMouseWheel = ' javascript:return big (This) ' title= ' 2009-8-11-19.22.06 ' style= ' border-right:0px ; border-top:0px; Display:inline; border-left:0px; border-bottom:0px "height=" "alt=" 2009-8-11-19.22.06 "src=" http://www.bkjia.com/uploadfile/2013/0904/ 20130904095417528.jpg "width=" 980 "border=" 0 "/>
Program Explanation:
-
- include ("phpmydatagrid.class.php");
- $objGrid = New DataGrid;
- $objGrid ->closetags (TRUE);
- $objGrid ->friendlyhtml ();
- $objGrid ->methodform ("get");
- //Connect to database
- $objGrid ->conectadb ("127.0.0.1", "root ", " root", "guru"); //Encrypt string
- $objGrid ->salt ("myc0defor5tr0ng3r-pro3ection");
- $objGrid ->language ("en");
- ///Last column shows the function keys, left-to-right features "new key", "Edit Key", "Delete key", "Browse key".
- $objGrid ->buttons (true,true,true,true);
- //The form name generated when the value is modified
- $objGrid ->form (' employee ', true);
- //Can retrieve column name
- $objGrid ->searchby ("Name,lastname");
- //tables that need to be read
- $objGrid ->tabla ("Employees");
- //index value for modifying data
- $objGrid ->keyfield ("id");
- //page shows the number of rows
- $objGrid ->datarows (20);
- //default sort mode
- $objGrid ->orderby ("name", "ASC");
- //Display column settings, related settings can refer to phpmydatagrid.class.php
- $objGrid ->formatcolumn ("id", "id Employee",5, 5, 1, "$", "Center" , "integer" );
- $objGrid ->formatcolumn ("name", "name",0 , 150 , "left");
- $objGrid ->formatcolumn ("LastName", "Last name",0 , " ", " left ");
- $objGrid ->formatcolumn ("age", "Age",5, 5, 0, " A", " Right "); //Custom date format
- $objGrid->formatcolumn ("Afiliation", "Afiliation Date", ten, 0 ," the", "Center", "date:dmy:/");//edit can be customized to mode $objGrid->formatcolumn ("status", "status", 5, 5, 0, "$", "left", " Select:1_single:2_married:3_divorced "); Edit can be customized as mode $objGrid->formatcolumn ("active", "active", 2, 2, 0, "" "," center "," Check:No:Yes ");//Custom currency display form $ Objgrid->formatcolumn ("Salary", "salary", ten, 0, "n", "right", "money:€");//data is displayed as a histogram $objGrid Formatcolumn ("Workeddays", "Work Days", 5, 2, 0, "a", "right", "chart:percent:val:31"); $objGrid->checkable (); $objGrid->setheader (); $objGrid->ajax (' silent '); Echo ' Phpdatagrid ' center > '; Generate DataGrid $objGrid->grid (); echo ';//Close database connection $objGrid->desconectar (); ?> 3. Oracle-based introduction for Oracle read mainly to the phpmydatagrid.class.php in the connection with the MySQL function modified to Oracle, this article is through Sqlrelay (refer to http://www.bkjia.com/ Phpjc/445682.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/445682.htmltecharticle recently wanted to do something with the DataGrid function through PHP, This allows you to directly modify the contents of a table in the database without developing a "new data page", "edit Page", ...