server_processing.php 1.8 KB

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