PHP implementation directly modify table content DataGrid function _php Tutorial

Source: Internet
Author: User
Tags delete key vars
Recently want to do a function of the DataGrid through PHP, so that you can directly modify the contents of the table in the database, without the development of "new data Page", "edit Page", and so on the Internet to find, similar things also have a few, open source, paid to have, but basically is based on MySQL. Because of the need to connect to Oracle so from two times development and page style personally feel phpmydatagrid is better to get started. This article begins with a MySQL-based approach, and briefly introduces two development for Oracle connectivity (based on Sqlrelay).

1. Creating a test database and tables

 
 
  1. Create database ' Guru ';
  2. Use ' Guru ';
  3. CREATE TABLE ' Employees ' (
  4. ' ID ' int (6) not NULL auto_increment,
  5. ' name ' char (a) default NULL,
  6. ' LastName ' char (+) default NULL,
  7. ' salary ' float default NULL,
  8. ' age ' int (2) default NULL,
  9. ' Afiliation ' Date default NULL,
  10. ' status ' int (1) default NULL,
  11. ' active ' tinyint (1) default NULL,
  12. ' workeddays ' int (2) default NULL,
  13. ' photo ' char (+) default NULL,
  14. PRIMARY KEY (' id ')
  15. )
  16. INSERT INTO ' employees '
  17. (' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
  18. values (1, ' Ana ', ' Trujillo ', 2000,45, ' 2005-05-13 ', 1,1,10, ' 1.jpg ');
  19. INSERT INTO ' employees '
  20. (' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
  21. values (2, ' Jennifer ', ' Aniston ', 3500,23, ' 2004-10-22 ') , 1,0,0, ' 2.jpg ');
  22. INSERT INTO ' employees '
  23. (' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
  24. values (3, ' Michael ', ' Norman ', 1200,19, ' 2007-01-10 ', 1,1,5, ' 3.jpg ');
  25. INSERT INTO ' employees '
  26. (' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
  27. VALUES (4, ' Vanessa ', ' Black ', 6500,31, ' 2000-11-05 ') , 1,1,30, ' 4.jpg ');
  28. INSERT INTO ' employees '
  29. (' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
  30. values (5, ' Michael ', ' Strauss ', 3200,45, ' 2006-10-21 ', 2,0,22, ' 5.jpg ');
  31. INSERT INTO ' employees '
  32. (' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
  33. VALUES (6, ' William ', ' Brown ', 2300,21, ' 2001-03-10 ') , 3,1,10, ' 6.jpg ');
  34. INSERT INTO ' employees '
  35. (' id ', ' name ', ' LastName ', ' salary ', ' age ', ' afiliation ', ' status ', ' active ', ' workeddays ', ' photo ')
  36. VALUES (7, ' Lucca ', ' Normany ', 2800,36, ' 2006-10-02 ', 3,1,20, ' 7.jpg ');

2. Introduction to PHP Programs

Phpmydatagrid mainly through the phpmydatagrid.class.php,dgscripts.js to achieve, in total add up to 100kB, is a small software. For these two files are not much to say, interested students can "pack away" back to slowly product. This paper mainly introduces the use method of the software, i.e. instance datagrid_for_mysql.php. First 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=" "alt=" 2009-8-11-19.22.06 "src=" http://www.bkjia.com/uploadfile/2013/0904/ 20130904095417528.jpg "width=" 980 "border=" 0 "/>

Program Explanation:

 
 
  1. include ("phpmydatagrid.class.php");
  2. $objGrid = New DataGrid;
  3. $objGrid ->closetags (TRUE);
  4. $objGrid ->friendlyhtml ();
  5. $objGrid ->methodform ("get");
  6. //Connect to database
  7. $objGrid ->conectadb ("127.0.0.1", "root ", " root", "guru"); //Encrypt string
  8. $objGrid ->salt ("myc0defor5tr0ng3r-pro3ection");
  9. $objGrid ->language ("en");
  10. ///Last column shows the function keys, left-to-right features "new key", "Edit Key", "Delete key", "Browse key".
  11. $objGrid ->buttons (true,true,true,true);
  12. //The form name generated when the value is modified
  13. $objGrid ->form (' employee ', true);
  14. //Can retrieve column name
  15. $objGrid ->searchby ("Name,lastname");
  16. //tables that need to be read
  17. $objGrid ->tabla ("Employees");
  18. //index value for modifying data
  19. $objGrid ->keyfield ("id");
  20. //page shows the number of rows
  21. $objGrid ->datarows (20);
  22. //default sort mode
  23. $objGrid ->orderby ("name", "ASC");
  24. //Display column settings, related settings can refer to phpmydatagrid.class.php
  25. $objGrid ->formatcolumn ("id", "id Employee",5, 5, 1, "$", "Center" , "integer" );
  26. $objGrid ->formatcolumn ("name", "name",0 , 150 , "left");
  27. $objGrid ->formatcolumn ("LastName", "Last name",0 , " ", " left ");
  28. $objGrid ->formatcolumn ("age", "Age",5, 5, 0, " A", " Right "); //Custom date format
  29. $objGrid->formatcolumn ("Afiliation", "Afiliation Date", ten, 0 ," the", "Center", "date:dmy:/");//edit can be customized to mode $objGrid->formatcolumn ("status", "status", 5, 5, 0, "$", "left", " Select:1_single:2_married:3_divorced "); Edit can be customized as mode $objGrid->formatcolumn ("active", "active", 2, 2, 0, "" "," center "," Check:No:Yes ");//Custom currency display form $ Objgrid->formatcolumn ("Salary", "salary", ten, 0, "n", "right", "money:€");//data is displayed as a histogram $objGrid Formatcolumn ("Workeddays", "Work Days", 5, 2, 0, "a", "right", "chart:percent:val:31"); $objGrid->checkable (); $objGrid->setheader (); $objGrid->ajax (' silent '); Echo ' Phpdatagrid ' center > '; Generate DataGrid $objGrid->grid (); echo ';//Close database connection $objGrid->desconectar (); ?> 3. Oracle-based introduction for Oracle read mainly to the phpmydatagrid.class.php in the connection with the MySQL function modified to Oracle, this article is through Sqlrelay (refer to http://www.bkjia.com/ Phpjc/445682.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/445682.htmltecharticle recently wanted to do something with the DataGrid function through PHP, This allows you to directly modify the contents of a table in the database without developing a "new data page", "edit Page", ... 

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.