Use PHP to implement the DataGrid Function

Source: Internet
Author: User
Welcome to the Linux community forum, and interact with 2 million technical staff. Recently, I want to implement the DataGrid function through PHP. In this way, I can directly modify the table content in the database without development. as a result, I found several similar items on the Internet, including open-source and paid items, but they are basically based on MySQL. Connection Or

Welcome to the Linux community forum, and interact with 2 million technical staff> recently, I want to create something to implement the DataGrid function through PHP, so that I can directly modify the table content in the database without development. as a result, I found several similar items on the Internet, including open-source and paid items, but they are basically based on MySQL. Connection Or

Welcome to the Linux community forum and interact with 2 million technicians>

Recently, I want to implement the DataGrid function through PHP, so that I can directly modify the table content in the database without development. as a result, I found several similar items on the Internet, including open-source and paid items, but they are basically based on MySQL. Because you need to connect to Oracle, from the secondary development and page style, I personally think phpMyDataGrid is better to use. This article first introduces how to use MySQL, and then briefly introduces the secondary development of Oracle connection (based on sqlrelay.

1. Create a test database and table

Reference content is as follows:
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:

Reference content is as follows:

// 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 ");
// Custom Date Format $ objGrid-> FormatColumn ("afiliation", "Afiliation date", 10, 10, 0, "100", "center", "Date: dmy: /");
// You can customize itMode $ 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 introduction

For Oracle reading, phpmydatagrid is mainly used. class. in php and MySQL connection function modified to Oracle, this article is through sqlrelay (can refer to the http://sqlrelay.sourceforge.net/) for Oracle connection, of course, you can also use the built-in PHP OCI8 module (low efficiency) and save it as phporadatagrid. class. php can be called in other programs (datagrid_for_oracle.php. All the programs involved above can be found in the compressed package.

Hope to be useful to everyone!

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.