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');
phpMyDataGrid主要是通過phpmydatagrid.class.php,dgscripts.JS來實現的,總共加起來不到100kB,又是一個小巧的軟件。對於這兩個文件就不多講了,感興趣的同學可以“打包帶走”回去慢慢品。主要介紹該軟件的使用方法,即實例datagrid_for_MySQL.PHP。先看一下頁面示意圖:
程序講解:
<?PHP include ("phpmydatagrid.class.PHP"); $objGrid = new datagrid; $objGrid->closeTags(true); $objGrid->frIEndlyHtml(); $objGrid->methodForm("get"); //連接數據庫 $objGrid->conectadb("127.0.0.1", "root", "root", "guru");
//加密字符串 $objGrid->salt("Myc0defor5tr0ng3r-Pro3EctiOn"); $objGrid->language("en"); //最後一列顯示的功能鍵,從左向右功能為“新增鍵”、“編輯鍵”、“刪除鍵”、“浏覽鍵”。 $objGrid->buttons(true,true,true,true); //修改數值時產生的Form名稱 $objGrid->form('employee', true); //可檢索列名 $objGrid->searchby("name,lastname"); //需要讀取的表 $objGrid->tabla("employees"); //索引值用於修改數據 $objGrid->keyfIEld("id"); //分頁顯示行數 $objGrid->datarows(20); //默認排序方式 $objGrid->orderby("name", "ASC"); //顯示列設置,相關設置可參考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");
//自定義日期格式 $objGrid->FormatColumn("afiliation", "Afiliation Date", 10, 10, 0, "100", "center", "date:dmy:/");
//編輯時可以自定義為<Select>模式 $objGrid->FormatColumn("status", "Status", 5, 5, 0, "60", "left", "select:1_Single:2_MarrIEd:3_Divorced"); //編輯時可以自定義為<CheckBox>模式 $objGrid->FormatColumn("active", "Active", 2, 2, 0,"50", "center", "check:No:Yes");
//自定義貨幣顯示形式 $objGrid->FormatColumn("salary", "Salary", 10, 10, 0, "90", "right", "money:€");
//將數據以柱狀圖顯示 $objGrid->FormatColumn("workeddays", "Work days", 5, 2, 0, "50", "right", "chart:percent:val:31"); $objGrid->checkable(); $objGrid->setHeader(); $objGrid->AJax('silent'); echo '<Html> <head><title>PHPDataGrid</title></head> <body><div align="center"><br />'; //生成DataGrid $objGrid->grid(); echo '</div></body></Html>';
//關閉數據庫連接 $objGrid->desconectar(); ?>
對於Oracle的讀取主要是把phpmydatagrid.class.PHP中與MySQL連接的函數修改為Oracle,本篇是通過sqlrelay(可參考http://sqlrelay.sourceforge.Net/)進行的Oracle連接,當然也可以使用PHP自帶的OCI8模塊(效率有些低),修改後另存為phporadatagrid.class.php即可在其他程序(datagrid_for_Oracle.PHP)中調用。以上涉及的所有程序均可在壓縮包中找到。
希望對大家有用!