Skip to content

Commit 644ed19

Browse files
committed
phpGrid database content management demo application
Online tutorial: http://phpgrid.com/example/database-content-administration-application-1 5-lines-php-code/
0 parents  commit 644ed19

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed

db-admin-template.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<title>phpGrid - DB Content Admin Demo</title>
6+
</head>
7+
<body>
8+
9+
<style type='text/css'>
10+
.wrapper{
11+
width: 100%;
12+
margin: 0 auto;
13+
}
14+
.header{
15+
float: left;
16+
width: 100%;
17+
text-align: center;
18+
}
19+
.wrapright{
20+
float: left;
21+
width: 100%;
22+
}
23+
.right{
24+
margin-left: 310px;
25+
height: 200px;
26+
}
27+
.left{
28+
float: left;
29+
width: 300px;
30+
margin-left: -100%;
31+
height: 200px;
32+
}
33+
body {
34+
padding: 15px;
35+
margin: 15px;
36+
}
37+
</style>
38+
39+
<div class="wrapper">
40+
<div class="header">
41+
<h1>2-column template</h1>
42+
</div>
43+
<div class="wrapright">
44+
<div class="right">
45+
</div>
46+
</div>
47+
<div class="left">
48+
</div>
49+
</div>
50+
51+
</body>
52+
</html>

db_admin.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
use phpGrid\C_DataGrid;
3+
4+
require_once("phpGridx/conf.php");
5+
6+
?>
7+
<!DOCTYPE html>
8+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
9+
<head>
10+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
11+
<title>DB Admin</title>
12+
</head>
13+
<body>
14+
15+
<style type='text/css'>
16+
.wrapper{
17+
width: 100%;
18+
margin: 0 auto;
19+
}
20+
.header{
21+
float: left;
22+
width: 100%;
23+
text-align: center;
24+
}
25+
.wrapright{
26+
float: left;
27+
width: 100%;
28+
}
29+
.right{
30+
margin-left: 310px;
31+
height: 200px;
32+
}
33+
.left{
34+
float: left;
35+
width: 300px;
36+
margin-left: -100%;
37+
height: 200px;
38+
}
39+
body {
40+
padding: 15px;
41+
margin: 15px;
42+
}
43+
</style>
44+
45+
<div class="wrapper">
46+
<div class="header">
47+
<h1>Database Table Data CRUD Admin Console</h1>
48+
</div>
49+
<div class="wrapright">
50+
<div class="right">
51+
<?php
52+
$schemaName = (isset($_GET['TABLE_SCHEMA']) && isset($_GET['TABLE_SCHEMA']) !== '') ? $_GET['TABLE_SCHEMA'] : 'sampledb';
53+
$tableName = (isset($_GET['TABLE_NAME']) && isset($_GET['TABLE_NAME']) !== '') ? $_GET['TABLE_NAME'] : 'orders';
54+
55+
//$dg = new C_DataGrid("SELECT * FROM $schemaName.$tableName");
56+
57+
$dg = new C_DataGrid("SELECT * FROM $tableName",'orderNumber', "$tableName",
58+
array("hostname"=>"localhost",
59+
"username"=>"root",
60+
"password"=>"",
61+
"dbname"=>$schemaName,
62+
"dbtype"=>"mysql",
63+
"dbcharset"=>"utf8"));
64+
$dg->set_caption(strtoupper("$schemaName.$tableName"));
65+
66+
$dg->enable_autowidth(true);
67+
$dg->enable_edit();
68+
$dg->set_scroll(true);
69+
$dg->enable_global_search(true);
70+
71+
// uncomment to set width to parent DIV instead
72+
$dg->before_script_end .= 'setTimeout(function(){$(window).bind("resize", function() {
73+
phpGrid_'. $tableName .'.setGridWidth($(".right").width());
74+
}).trigger("resize");}, 0)';
75+
76+
$dg -> display();
77+
?>
78+
</div>
79+
</div>
80+
<div class="left">
81+
<?php
82+
// schema list
83+
$dbs = new C_DataGrid("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA", "SCHEMA_NAME", "INFORMATION_SCHEMA.SCHEMATA");
84+
$dbs->set_dimension('300px');
85+
$dbs->set_pagesize(999)->set_scroll(true);
86+
87+
// table list
88+
$tbl = new C_DataGrid("SELECT TABLE_NAME, TABLE_SCHEMA, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES", "TABLE_NAME", "INFORMATION_SCHEMA.TABLES");
89+
$tbl->set_col_hidden('TABLE_SCHEMA');
90+
$tbl->set_pagesize(999)->set_scroll(true);
91+
$tbl -> set_col_dynalink("TABLE_NAME", "db_admin.php", array("TABLE_NAME", "TABLE_SCHEMA"), '', "_top");
92+
//$tbl->set_col_title('TABLE_NAME', 'Name')->set_col_title('TABLE_ROWS', 'Count');
93+
94+
$dbs->set_subgrid($tbl, 'TABLE_SCHEMA', 'SCHEMA_NAME');
95+
$dbs->display();
96+
?>
97+
</div>
98+
</div>
99+
100+
TODO: add form only mode
101+
102+
103+
</body>
104+
</html>

0 commit comments

Comments
 (0)