PHPDataGrid implementation code _ PHP Tutorial

Source: Internet
Author: User
PHPDataGrid implementation code. 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 phpMyDataGrid for secondary development and page styles because you need to connect to Oracle. 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

The code 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,
'A' 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 'ployees'
('Id', 'name', 'lastname', 'salary ', 'age', 'afiliation', 'status', 'active', 'workeddays ', 'photo ')
Values (1, 'Ana ', 'trujillo', 2005, 45, '2017-05-13', 10, '1.jpg ');
Insert into 'ployees'
('Id', 'name', 'lastname', 'salary ', 'age', 'afiliation', 'status', 'active', 'workeddays ', 'photo ')
Values (2, 'Jennifer ', 'aniston', 2004, 23, '2017-10-22', 0, '2.jpg ');
Insert into 'ployees'
('Id', 'name', 'lastname', 'salary ', 'age', 'afiliation', 'status', 'active', 'workeddays ', 'photo ')
Values (3, 'Michael ', 'Norman', 2007, '1970-01-10 ', 5, '3.jpg ');
Insert into 'ployees'
('Id', 'name', 'lastname', 'salary ', 'age', 'afiliation', 'status', 'active', 'workeddays ', 'photo ')
Values (4, 'wasa', 'black', 2000, 31, '2017-11-05 ', 30, '4.jpg ');
Insert into 'ployees'
('Id', 'name', 'lastname', 'salary ', 'age', 'afiliation', 'status', 'active', 'workeddays ', 'photo ')
Values (5, 'Michael ', 'Strauss', 2006, 45, '2017-10-21 ', 22, '5.jpg ');
Insert into 'ployees'
('Id', 'name', 'lastname', 'salary ', 'age', 'afiliation', 'status', 'active', 'workeddays ', 'photo ')
Values (6, 'William', 'Brown ', 2001, 21, '2017-03-10', 10, '6.jpg ');
Insert into 'ployees'
('Id', 'name', 'lastname', 'salary ', 'age', 'afiliation', 'status', 'active', 'workeddays ', 'photo ')
Values (7, 'lucca ', 'northeast', 2006, 36, '2017-10-02', 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:

The code is as follows:


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 ");
// The function key displayed in the last column. The options include "add key", "Edit key", "Delete key", and "browse key ".
$ ObjGrid-> buttons (true, true );
// Modify the Form name generated by the numeric value
$ ObjGrid-> form ('employee', true );
// Searchable column name
$ ObjGrid-> searchby ("name, lastname ");
// The table to be read
$ ObjGrid-> tabla ("employees ");
// The index value is used to modify data.
$ ObjGrid-> keyfield ("id ");
// Number of lines displayed by 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 "); // display the custom currency$ ObjGrid-> FormatColumn ("salary", "Salary", 10, 10, 0, "90", "right", "money: € "); // display data in a column 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 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!4. source program downloadBytes. This article first introduces how to use MySQL, and then briefly introduces...

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.