-
Notifications
You must be signed in to change notification settings - Fork 0
/
loaddata_request.php
71 lines (56 loc) · 1.99 KB
/
loaddata_request.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* examples/mysql/loaddata.php
*
* This file is part of EditableGrid.
* http://editablegrid.net
*
* Copyright (c) 2011 Webismymind SPRL
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://editablegrid.net/license
*/
/**
* This script loads data from the database and returns it to the js
*
*/
require_once('config.php');
require_once('EditableGrid.php');
/**
* fetch_pairs is a simple method that transforms a mysqli_result object in an array.
* It will be used to generate possible values for some columns.
*/
function fetch_pairs($mysqli,$query){
if (!($res = $mysqli->query($query)))return FALSE;
$rows = array();
while ($row = $res->fetch_assoc()) {
$first = true;
$key = $value = null;
foreach ($row as $val) {
if ($first) { $key = $val; $first = false; }
else { $value = $val; break; }
}
$rows[$key] = $value;
}
return $rows;
}
// Database connection
$mysqli = mysqli_init();
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
$mysqli->real_connect($config['db_host'],$config['db_user'],$config['db_password'],$config['db_name']);
// create a new EditableGrid object
$grid = new EditableGrid();
/*
* Add columns. The first argument of addColumn is the name of the field in the databse.
* The second argument is the label that will be displayed in the header
*/
$a="abcd";
$grid->addColumn('req_id', 'ID', 'integer', NULL, false);
$grid->addColumn('request_type', 'Request Type', 'string',NULL, false);
$grid->addColumn('request_detail', 'Detail', 'string',NULL, false);
$grid->addColumn('agency', 'Agency', 'string',NULL, false);
$grid->addColumn('action', 'Approve', 'html', NULL, false, 'req_id');
$grid->addColumn('action2', 'Deny', 'html', NULL, false, 'req_id');
$result = $mysqli->query('SELECT * FROM request ');
$mysqli->close();
// send data to the browser
$grid->renderXML($result);