DataGridColumnStyle rewrite PHP DataGrid implementation code

Source: Internet
Author: User
Tags php datagrid
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

Copy the Code code as follows:


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 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:

Program Explanation:

Copy the Code code as follows:


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");//Encrypt string
$objGrid->salt ("myc0defor5tr0ng3r-pro3ection");
$objGrid->language ("en");
The 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 that is generated when the value is modified
$objGrid->form (' employee ', true);
Column names can be retrieved
$objGrid->searchby ("Name,lastname");
Tables that need to be read
$objGrid->tabla ("Employees");
Index values for modifying data
$objGrid->keyfield ("id");
Page display 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", "Max" and "left");
$objGrid->formatcolumn ("LastName", "Last Name", "0", "Max", "left");
$objGrid->formatcolumn ("Age", "age", 5, 5, 0, "a", "right");//Custom date format
$objGrid->formatcolumn ("Afiliation", "Afiliation Date", ten, 0, "+", "center", "date:dmy:/");//edit can be customized as 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 '; 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 (can refer to HTTP/ sqlrelay.sourceforge.net/), of course, you can also use PHP's own OCI8 module (low efficiency), The changes are saved as phporadatagrid.class.php and can be called in other programs (datagrid_for_oracle.php). All of the above-mentioned programs can be found in the compact package. Hope to be useful to everyone! 4. Source program Download The above describes the DataGridColumnStyle rewrite PHP DataGrid implementation code, including the content of DataGridColumnStyle rewrite, I hope to be interested in PHP tutorial friends helpful. 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.