PHP code for directly modifying the table content DataGrid function

Source: Internet
Author: User
Recently, I want to implement the DataGrid function using PHP, so that I can directly modify the table content in the database without developing [add data Page] and [edit page ], this article first introduces how to use MySQL, and then briefly introduces the secondary development of Oracle connection (based on sqlrelay. Because you need to connect to Oracle, from the secondary development and page style, I personally think phpMyDataGrid is better to use.
1. create a test database and table

create database `guru`;  USE `guru`;  CREATE TABLE `employees` (    `id` int(6) NOT NULL auto_increment,    `name` char(20) default NULL,    `lastname` char(20) 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(30) 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. PHP program introduction

PhpMyDataGrid is mainly implemented through phpmydatagrid. class. php and dgscripts. js. The total size is less than kB, and it is a small software. I will not talk about these two files much. if you are interested, you can "pack and take it" back to the product. This section describes how to use the software, that is, the instance datagrid_for_mysql.php. Let's take a look at the page:

Program description:

<? Php include ("phpmydatagrid. class. php "); $ objGrid = new datagrid; $ objGrid-> closeTags (true); $ objGrid-> friendlyHTML (); $ objGrid-> methodForm (" get "); // connect to the database $ objGrid-> conectadb ("127.0.0.1", "root", "root", "guru "); // encrypted string $ objGrid-> salt ("Myc0defor5tr0ng3r-Pro3EctiOn"); $ objGrid-> language ("en"); // Function key displayed in the last column, the left-to-right functions include "add key", "Edit key", "Delete key", and "browse key ". $ ObjGrid-> buttons (true, true); // Form name generated when the value is modified $ objGrid-> form ('employe', true ); // you can retrieve the column name $ objGrid-> searchby ("name, lastname"); // The table to be read $ objGrid-> tabla ("employees "); // the index value is used to modify the data $ objGrid-> keyfield ("id"); // The number of lines displayed on the page $ objGrid-> datarows (20 ); // Default sorting method $ objGrid-> orderby ("name", "ASC"); // Display column settings. For more information, see phpmydatagrid. class. php $ objGrid-> FormatColumn ("id", "ID Employee", 5, 5, 1, "50", "center", "integer "); $ objGrid-> FormatColumn ("name", "Name", 30, 30, 0, "150", "left"); $ objGrid-> FormatColumn ("lastname ", "Last name", 30, 30, 0, "150", "left"); $ objGrid-> FormatColumn ("age", "Age", 5, 5, 0, "50", "right"); // The custom Date format $ objGrid-> FormatColumn ("afiliation", "Afiliation Date", 10, 10, 0, "100 ", "center", "date: dmy:/"); // You can customizeMode $ objGrid-> FormatColumn ("status", "Status", 5, 5, 0, "60", "left", "select: distinct single: 2_Married: 3_Divorced "); // You can customize itMode $ objGrid-> FormatColumn ("active", "Active", 2, 2, 0, "50", "center", "check: No: Yes "); // custom currency display format $ objGrid-> FormatColumn ("salary", "Salary", 10, 10, 0, "90", "right", "money: € "); // display data in a bar chart $ objGrid-> FormatColumn (" workeddays "," Work days ", 5, 2, 0," 50 "," right ", "chart: percent: val: 31"); $ objGrid-> checkable (); $ objGrid-> setHeader (); $ objGrid-> ajax ('silent'); echo'    PHPDataGrid    '; // Generate the DataGrid $ objGrid-> grid (); echo''; // Close the database connection $ objGrid-> desconectar ();?>3. Oracle-based introductionFor Oracle reading, phpmydatagrid is mainly used. class. in php, the function connected to MySQL is changed to Oracle. This article uses sqlrelay for Oracle connection. of course, you can also use the OCI8 module provided by PHP (which is somewhat inefficient) and save it as phporadatagrid after modification. class. php can be called in other programs (datagrid_for_oracle.php.The above is to teach you how to directly modify the table content DataGrid function in PHP throughout the process, as well as understanding about the database, I hope this article will help you learn.

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.