PHP DataGrid function: Modify the contents of the table directly

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags based can directly class connect create data date default

Recently wanted to do a DataGrid function through PHP things, so that you can directly modify the contents of the database table, without the development of [new data page], [edit page], so looking for the Internet to find something similar A, open source, have paid, but basically are based on MySQL. Due to the need to connect to Oracle personally from the secondary development and page style phpMyDataGrid is still quite good. This article first introduces the use of MySQL-based method, and then briefly introduce the secondary development of the Oracle connection (based on sqlrelay).

1. Create test database and table create database `guru`; USE` guru`; CREATE TABLE `employees` (` id` int (6) NOT NULL auto_increment, `name` char 20) default NULL, `salary` float default NULL,` age` int (2) default NULL, `afiliation` date default NULL,` status` int (1) default NULL, `active` tinyint 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`, `na me`, `lastname`,` salary`, `age`,` afiliation`, `status`,` active`, `workeddays`,` photo`) values ​​(4, Vanessa, Black, 6500,31, 2000-11 -0.5,1,1,30, 4.jpg); insert into employees (id, name, lastname, salary, age, afiliation, status, `,` 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);

phpMyDataGrid mainly by phpmydatagrid.class.php, dgscripts.js to achieve, together add up to less than 100kB, but also a compact software. For these two documents is not much talked about, interested students can "pack away" back slowly products. Mainly introduces the use of the software, namely datagrid_for_mysql.php. Program explanation:

<? php include ("phpmydatagrid.class.php"); objGrid = new datagrid; objGrid-> closeTags (true) > conectadb ("127.0.0.1", "root", "root", "guru");
// Encrypted string objGrid-> salt ("Myc0defor5tr0ng3r-Pro3EctiOn"); objGrid-> language ("en"); // The last column shows the function keys, Key "," delete key "," browse key ". objGrid-> buttons (true, true, true, true); // the name of the Form generated when modifying the value objGrid-> form (employee, true); // retrievable column name objGrid-> searchby ("name, lastname") ; / / Need to read the table objGrid-> tabla ("employees"); / / index value is used to modify the data objGrid-> keyfield ("id"); / / page shows the number of rows objGrid-> datarows (20); // default order objGrid-> orderby ("name", "ASC"); / / display column settings related settings phpmydatagrid.class.php objGrid-> FormatColumn ("id", "ID Employee", 5, 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: /");
// Can be customized to <Select> mode objGrid-> FormatColumn ("status", "Status", 5, 5, 0, "60", "left", "select: 1_Single: 2_Married: 3_Divorced"); // Can be customized as <CheckBox> mode objGrid-> FormatColumn ("active", "Active", 2, 2, 0, "50", "center", "check: NYes");
// custom currency display objGrid-> FormatColumn ("salary", "Salary", 10, 10, 0, "90", "right", "money: & euro;");
// Show the data as a histogram objGrid-> FormatColumn ("workeddays", "Work days", 5, 2, 0, "50", "right", "chart: percent: val: 31"); objGrid-> objGrid-> ajax (silent); echo <html> <head> <title> PHPDataGrid </ title> </ head> <body> <div align = "center"> < // generate a DataGrid objGrid-> grid (); echo </ div> </ body> </ html>;
// Close the database connection objGrid-> desconectar ();?>

Based on Oracle Introduction

Oracle read mainly to phpmydatagrid.class.php connected with the MySQL function is modified to Oracle, this article is through sqlrelay (see http://sqlrelay.sourceforge.net/ Oracle connection, of course, can OCI8 module comes with PHP (some low efficiency), modified as phporadatagrid.class.php can be called in other programs (datagrid_for_oracle.php). All of the above procedures can be found in the archive.
hope its good for U.S!

Related Article

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.