1
|
<?php
|
2
|
|
3
|
/*
|
4
|
* DataTables example server-side processing script.
|
5
|
*
|
6
|
* Please note that this script is intentionally extremely simply to show how
|
7
|
* server-side processing can be implemented, and probably shouldn't be used as
|
8
|
* the basis for a large complex system. It is suitable for simple use cases as
|
9
|
* for learning.
|
10
|
*
|
11
|
* See http://datatables.net/usage/server-side for full details on the server-
|
12
|
* side processing requirements of DataTables.
|
13
|
*
|
14
|
* @license MIT - http://datatables.net/license_mit
|
15
|
*/
|
16
|
|
17
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
18
|
* Easy set variables
|
19
|
*/
|
20
|
|
21
|
// DB table to use
|
22
|
$table = 'datatables_demo';
|
23
|
|
24
|
// Table's primary key
|
25
|
$primaryKey = 'id';
|
26
|
|
27
|
// Array of database columns which should be read and sent back to DataTables.
|
28
|
// The `db` parameter represents the column name in the database, while the `dt`
|
29
|
// parameter represents the DataTables column identifier. In this case simple
|
30
|
// indexes
|
31
|
$columns = array(
|
32
|
array( 'db' => 'first_name', 'dt' => 0 ),
|
33
|
array( 'db' => 'last_name', 'dt' => 1 ),
|
34
|
array( 'db' => 'position', 'dt' => 2 ),
|
35
|
array( 'db' => 'office', 'dt' => 3 ),
|
36
|
array(
|
37
|
'db' => 'start_date',
|
38
|
'dt' => 4,
|
39
|
'formatter' => function( $d, $row ) {
|
40
|
return date( 'jS M y', strtotime($d));
|
41
|
}
|
42
|
),
|
43
|
array(
|
44
|
'db' => 'salary',
|
45
|
'dt' => 5,
|
46
|
'formatter' => function( $d, $row ) {
|
47
|
return '$'.number_format($d);
|
48
|
}
|
49
|
)
|
50
|
);
|
51
|
|
52
|
$sql_details = array(
|
53
|
'user' => '',
|
54
|
'pass' => '',
|
55
|
'db' => '',
|
56
|
'host' => ''
|
57
|
);
|
58
|
|
59
|
|
60
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
61
|
* If you just want to use the basic configuration for DataTables with PHP
|
62
|
* server-side, there is no need to edit below this line.
|
63
|
*/
|
64
|
require( 'ssp.class.php' );
|
65
|
|
66
|
echo $_GET['callback'].'('.json_encode(
|
67
|
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
|
68
|
).');';
|
69
|
|