PHP allows you to directly modify the table content DataGrid.

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 the [add data page] and [Edit page ], 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

 
 
  1. create database `guru`;  
  2.  
  3. USE `guru`;  
  4.  
  5. CREATE TABLE `employees` (  
  6.       `id` int(6) NOT NULL auto_increment,  
  7.       `name` char(20) default NULL,  
  8.       `lastname` char(20) default NULL,  
  9.       `salary` float default NULL,  
  10.       `age` int(2) default NULL,  
  11.       `afiliation` date default NULL,  
  12.       `status` int(1) default NULL,  
  13.       `active` tinyint(1) default NULL,  
  14.       `workeddays` int(2) default NULL,  
  15.       `photo` char(30) default NULL,  
  16.       PRIMARY KEY  (`id`)  
  17. )  
  18.  
  19. insert into `employees`  
  20.     (`id`,`name`,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`)   
  21.     values (1, 'Ana', 'Trujillo',2000,45, '2005-05-13',1,1,10, '1.jpg');  
  22. insert into `employees`   
  23.     (`id`,`name`,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`)  
  24.     values (2, 'Jennifer', 'Aniston',3500,23, '2004-10-22',1,0,0, '2.jpg');  
  25. insert into `employees`   
  26.     (`id`,`name`,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`)  
  27.     values (3, 'Michael', 'Norman',1200,19, '2007-01-10',1,1,5, '3.jpg');  
  28. insert into `employees`   
  29.     (`id`,`name`,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`)  
  30.     values (4, 'Vanessa', 'Black',6500,31, '2000-11-05',1,1,30, '4.jpg');  
  31. insert into `employees`   
  32.     (`id`,`name`,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`)  
  33.     values (5, 'Michael', 'Strauss',3200,45, '2006-10-21',2,0,22, '5.jpg');  
  34. insert into `employees`   
  35.     (`id`,`name`,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`)  
  36.     values (6, 'William', 'Brown',2300,21, '2001-03-10',3,1,10, '6.jpg');  
  37. insert into `employees`   
  38.     (`id`,`name`,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`)  
  39.     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:

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'title = "2009-8-11-19.22.06" style = "border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px "height =" 270 "alt =" 2009-8-11-19.22.06 "src =" http://www.bkjia.com/uploadfile/2013/0904/20130904095417528.jpg "width =" 980 "border =" 0 "/>

Program description:

 
 
  1. <? Php
  2. Include ("phpmydatagrid. class. php ");
  3. $ ObjGrid = new datagrid;
  4. $ ObjGrid-> closeTags (true );
  5. $ ObjGrid-> friendlyHTML ();
  6. $ ObjGrid-> methodForm ("get ");
  7. // Connect to the database
  8. $ ObjGrid-> conectadb ("127.0.0.1", "root", "root", "guru"); // encrypted string
  9. $ ObjGrid-> salt ("Myc0defor5tr0ng3r-Pro3EctiOn ");
  10. $ ObjGrid-> language ("en ");
  11. // The function key displayed in the last column. The options include "add key", "Edit key", "delete key", and "Browse key ".
  12. $ ObjGrid-> buttons (true, true );
  13. // Modify the Form name generated by the numeric value
  14. $ ObjGrid-> form ('Employee', true );
  15. // Searchable column name
  16. $ ObjGrid-> searchby ("name, lastname ");
  17. // The table to be read
  18. $ ObjGrid-> tabla ("employees ");
  19. // The index value is used to modify data.
  20. $ ObjGrid-> keyfield ("id ");
  21. // Number of lines displayed by PAGE
  22. $ ObjGrid-> datarows (20 );
  23. // Default sorting method
  24. $ ObjGrid-> orderby ("name", "ASC ");
  25. // Display column settings. For more information, see phpmydatagrid. class. php.
  26. $ ObjGrid-> FormatColumn ("id", "ID Employee", 5, 5, 1, "50", "center", "integer ");
  27. $ ObjGrid-> FormatColumn ("name", "Name", 30, 30, 0, "150", "left ");
  28. $ ObjGrid-> FormatColumn ("lastname", "Last name", 30, 30, 0, "150", "left ");
  29. $ ObjGrid-> FormatColumn ("age", "Age", 5, 5, 0, "50", "right"); // custom Date Format
  30. $ ObjGrid-> FormatColumn ("afiliation", "Afiliation Date", 10, 10, 0, "100", "center", "date: dmy :/"); // The <Select> mode can be customized during editing.
  31. $ ObjGrid-> FormatColumn ("status", "Status", 5, 5, 0, "60", "left", "select: distinct single: 2_Married: 3_Divorced ");
  32. // The <CheckBox> mode can be customized during editing.
  33. $ ObjGrid-> FormatColumn ("active", "Active", 2, 2, 0, "50", "center", "check: No: Yes "); // display the custom currency
  34. $ ObjGrid-> FormatColumn ("salary", "Salary", 10, 10, 0, "90", "right", "money: & euro ;"); // display data in a column chart
  35. $ ObjGrid-> FormatColumn ("workeddays", "Work days", 5, 2, 0, "50", "right", "chart: percent: val: 31 ");
  36. $ ObjGrid-> checkable ();
  37. $ ObjGrid-> setHeader ();
  38. $ ObjGrid-> ajax ('silent ');
  39. Echo '
  40. <Head> <title> PHPDataGrid </title>
  41. <Body> <div align = "center"> <br/> ';
  42. // Generate the DataGrid
  43. $ ObjGrid-> grid ();
  44. Echo '</div> </body>
  45. $ ObjGrid-> desconectar ();
  46. ?>

3. Oracle-based introduction

For Oracle reading, the function connecting phpmydatagrid. class. php to MySQL is changed to Oracle. This article uses sqlrelay (see

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.