PHP直接修改表內(nèi)容DataGrid功能實(shí)現(xiàn)代碼
由于需要連接Oracle所以從二次開(kāi)發(fā)和頁(yè)面樣式來(lái)說(shuō)個(gè)人覺(jué)得phpMyDataGrid還是比較好上手。
1. 創(chuàng)建測(cè)試數(shù)據(jù)庫(kù)和表
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');
2. PHP程序介紹
phpMyDataGrid主要是通過(guò)phpmydatagrid.class.php,dgscripts.js來(lái)實(shí)現(xiàn)的,總共加起來(lái)不到100kB,又是一個(gè)小巧的軟件。對(duì)于這兩個(gè)文件就不多講了,感興趣的同學(xué)可以“打包帶走”回去慢慢品。主要介紹該軟件的使用方法,即實(shí)例 datagrid_for_mysql.php。先看一下頁(yè)面示意圖:
程序講解:
<?php include ("phpmydatagrid.class.php"); $objGrid = new datagrid; $objGrid->closeTags(true); $objGrid->friendlyHTML(); $objGrid->methodForm("get"); //連接數(shù)據(jù)庫(kù) $objGrid->conectadb("127.0.0.1", "root", "root", "guru");//加密字符串 $objGrid->salt("Myc0defor5tr0ng3r-Pro3EctiOn"); $objGrid->language("en"); //最后一列顯示的功能鍵,從左向右功能為“新增鍵”、“編輯鍵”、“刪除鍵”、“瀏覽鍵”。 $objGrid->buttons(true,true,true,true); //修改數(shù)值時(shí)產(chǎn)生的Form名稱(chēng) $objGrid->form('employee', true); //可檢索列名 $objGrid->searchby("name,lastname"); //需要讀取的表 $objGrid->tabla("employees"); //索引值用于修改數(shù)據(jù) $objGrid->keyfield("id"); //分頁(yè)顯示行數(shù) $objGrid->datarows(20); //默認(rèn)排序方式 $objGrid->orderby("name", "ASC"); //顯示列設(shè)置,相關(guān)設(shè)置可參考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:/");//編輯時(shí)可以自定義為<Select>模式 $objGrid->FormatColumn("status", "Status", 5, 5, 0, "60", "left", "select:1_Single:2_Married:3_Divorced"); //編輯時(shí)可以自定義為<CheckBox>模式 $objGrid->FormatColumn("active", "Active", 2, 2, 0,"50", "center", "check:No:Yes");//自定義貨幣顯示形式 $objGrid->FormatColumn("salary", "Salary", 10, 10, 0, "90", "right", "money:€");//將數(shù)據(jù)以柱狀圖顯示 $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>';//關(guān)閉數(shù)據(jù)庫(kù)連接 $objGrid->desconectar(); ?>
3. 基于Oracle簡(jiǎn)介
對(duì)于Oracle的讀取主要是把phpmydatagrid.class.php中與MySQL連接的函數(shù)修改為Oracle,本篇是通過(guò)sqlrelay進(jìn)行的Oracle連接,當(dāng)然也可以使用PHP自帶的OCI8模塊(效率有些低),修改后另存為phporadatagrid.class.php即可在其他程序(datagrid_for_oracle.php)中調(diào)用。
以上就是教大家PHP如何直接修改表內(nèi)容DataGrid功能的全過(guò)程,還有對(duì)數(shù)據(jù)庫(kù)的了解,希望本文對(duì)大家的學(xué)習(xí)有所幫助。
- PHP DataGrid 實(shí)現(xiàn)代碼
- PHP – EasyUI DataGrid 資料取的方式介紹
- PHP – EasyUI DataGrid 資料存的方式介紹
- winform用datagridview制作課程表實(shí)例
- EasyUi datagrid 實(shí)現(xiàn)表格分頁(yè)
- jQuery EasyUI datagrid實(shí)現(xiàn)本地分頁(yè)的方法
- c#中datagridview處理非綁定列的方法
- C#處理datagridview虛擬模式的方法
- C#中datagridview的EditingControlShowing事件用法實(shí)例
- C#實(shí)現(xiàn)給DataGrid單元行添加雙擊事件的方法
- 初識(shí)通用數(shù)據(jù)庫(kù)操作類(lèi)——前端easyui-datagrid,form(php)
- C#實(shí)現(xiàn)DataGridView控件行列互換的方法
- C#實(shí)現(xiàn)綁定DataGridView與TextBox之間關(guān)聯(lián)的方法
相關(guān)文章
POSIX 風(fēng)格和兼容 Perl 風(fēng)格兩種正則表達(dá)式主要函數(shù)的類(lèi)比(preg_match, preg_replace,
POSIX 風(fēng)格和兼容 Perl 風(fēng)格兩種正則表達(dá)式主要函數(shù)的類(lèi)比(preg_match, preg_replace, ereg, ereg_replace) ,需要的朋友可以參考下。2010-10-10php從csv文件讀取數(shù)據(jù)并輸出到網(wǎng)頁(yè)的方法
這篇文章主要介紹了php從csv文件讀取數(shù)據(jù)并輸出到網(wǎng)頁(yè)的方法,涉及php中fgetcsv函數(shù)及數(shù)組遍歷的使用技巧,需要的朋友可以參考下2015-03-03PHP面向?qū)ο蟪绦蛟O(shè)計(jì)中的self、static、parent關(guān)鍵字用法分析
這篇文章主要介紹了PHP面向?qū)ο蟪绦蛟O(shè)計(jì)中的self、static、parent關(guān)鍵字用法,結(jié)合實(shí)例形式分析了self、static、parent關(guān)鍵字功能、應(yīng)用場(chǎng)景及相關(guān)使用技巧,需要的朋友可以參考下2019-08-08php函數(shù)傳值的引用傳遞注意事項(xiàng)分析
這篇文章主要介紹了php函數(shù)傳值的引用傳遞注意事項(xiàng),涉及php配置文件的設(shè)置及數(shù)組函數(shù)的使用技巧,需要的朋友可以參考下2016-06-06php字符串分割函數(shù)explode的實(shí)例代碼
在php中分割一個(gè)字符串,我們可以使用函數(shù)explode(),其原型如下2013-02-02PHP中實(shí)現(xiàn)中文字符進(jìn)制轉(zhuǎn)換原理分析
中文字符編碼研究系列第四期,PHP實(shí)現(xiàn)中文字符進(jìn)制轉(zhuǎn)換原理分析,主要討論中文漢字轉(zhuǎn)換為十進(jìn)制和十六進(jìn)制的方法,并掌握轉(zhuǎn)換原理應(yīng)用于實(shí)際開(kāi)發(fā)。本文以GBK編碼字符為例,討論GBK編碼的字符轉(zhuǎn)換原理2011-12-12php的日期處理函數(shù)及uchome的function_coomon中日期處理函數(shù)的研究
經(jīng)常在用php的時(shí)候會(huì)碰到一個(gè)關(guān)于時(shí)間日期的問(wèn)題還有時(shí)區(qū)差異的問(wèn)題,以前作項(xiàng)目的時(shí)候會(huì)把時(shí)間搞錯(cuò),要么就是提前八小時(shí)了,要么那個(gè)時(shí)間就是驢唇不對(duì)馬嘴的,現(xiàn)在我就來(lái)深入研究一下這里面的各個(gè)函數(shù)及其用法2011-01-01