ids-objects.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 object
  25. // parameter names
  26. $columns = array(
  27. array(
  28. 'db' => 'id',
  29. 'dt' => 'DT_RowId',
  30. 'formatter' => function( $d, $row ) {
  31. // Technically a DOM id cannot start with an integer, so we prefix
  32. // a string. This can also be useful if you have multiple tables
  33. // to ensure that the id is unique with a different prefix
  34. return 'row_'.$d;
  35. }
  36. ),
  37. array( 'db' => 'first_name', 'dt' => 'first_name' ),
  38. array( 'db' => 'last_name', 'dt' => 'last_name' ),
  39. array( 'db' => 'position', 'dt' => 'position' ),
  40. array( 'db' => 'office', 'dt' => 'office' ),
  41. array(
  42. 'db' => 'start_date',
  43. 'dt' => 'start_date',
  44. 'formatter' => function( $d, $row ) {
  45. return date( 'jS M y', strtotime($d));
  46. }
  47. ),
  48. array(
  49. 'db' => 'salary',
  50. 'dt' => 'salary',
  51. 'formatter' => function( $d, $row ) {
  52. return '$'.number_format($d);
  53. }
  54. )
  55. );
  56. $sql_details = array(
  57. 'user' => '',
  58. 'pass' => '',
  59. 'db' => '',
  60. 'host' => ''
  61. );
  62. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  63. * If you just want to use the basic configuration for DataTables with PHP
  64. * server-side, there is no need to edit below this line.
  65. */
  66. require( 'ssp.class.php' );
  67. echo json_encode(
  68. SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
  69. );