快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

澳门新葡亰app在线下载:PHP实现DataGrid



近来想做一个经由过程PHP实现DataGrid功能的器械,这样可以直接改动数据库中表的内容,而不用开拓【新增数据页面】,【编辑页面】,于是乎在网上找了找,类似的器械也有几个,开源的、付费的都有,不过基础都是基于MySQL。因为必要连接Oracle以是从二次开拓和页面样式来说小我感觉phpMyDataGrid照样对照好上手。本篇首先先容基于MySQL的应用措施,再简单先容对付Oracle连接(基于sqlrelay)的二次开拓。

1. 创建测试数据库和表

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` ch澳门新葡亰app在线下载ar(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`,`lastna澳门新葡亰app在线下载me`,`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主如果经由过程phpmydatagrid.class.php,dgscripts.js来澳门新葡亰app在线下载实现的,统共加起来不到100kB,又是一个小巧的软件。对付这两个文件就不多讲了,感兴趣的同砚可以“打包带走”回去逐步品。主要先容该软件的应用措施,澳门新葡亰app在线下载即实例datagrid_for_mysql.php。先看一下页面示意图:

法度榜样解说:

("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:/");

//编辑时可以自定义为模式

$objGrid->FormatColumn("status", "Status", 5, 5, 0, "60", "left", "select:1_Single:2_Married:3_Divorced");

//编辑时可以自定义为模式

$objGrid->FormatColumn("active", "Active", 2, 2, 0,"50", "center", "check:No:Yes");

//自定义泉币显示形式

$objGrid->FormatColumn("salary", "Salary", 10, 10, 0, "90", "right", "money:&澳门新葡亰app在线下载euro;");

//将数据以柱状图显示

$objGrid->FormatColumn("workeddays", "Work days", 5, 2, 0, "50", "right", "chart:percent:val:31");

$objGrid->checkable();

$objGrid->setHeader();

$objGrid->ajax('silent');

echo '

';

//天生DataGrid

$objGrid->grid();

echo '

';

//关闭数据库连接

$objGrid->desconectar();

?>

3. 基于Oracle简介

对付Oracle的读取主如果把phpmydatagrid.class.php中与MySQL连接的函数改动为Oracle,本篇是经由过程sqlrelay(可参考http://sqlrelay.sourceforge.net/)进行的Oracle连接,当然也可以应用PHP自带的OCI8模块(效率有些低),改动后另存为phporadatagrid.class.php即可在其他法度榜样(datagrid_for_oracle.php)中调用。以上涉及的所有法度榜样均可在压缩包中找到。

盼望对大年夜家有用!

4. 源法度榜样下载

http://bbs.fengfly.com/thread-89-1-1.html

转自:http://www.cnblogs.com/gnielee/archive/2009/08/11/1543911.html

您可能还会对下面的文章感兴趣: