ids-arrays.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 + the primary key column for the id
  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' => 0 ),
  38. array( 'db' => 'last_name', 'dt' => 1 ),
  39. array( 'db' => 'position', 'dt' => 2 ),
  40. array( 'db' => 'office', 'dt' => 3 ),
  41. array(
  42. 'db' => 'start_date',
  43. 'dt' => 4,
  44. 'formatter' => function( $d, $row ) {
  45. return date( 'jS M y', strtotime($d));
  46. }
  47. ),
  48. array(
  49. 'db' => 'salary',
  50. 'dt' => 5,
  51. 'formatter' => function( $d, $row ) {
  52. return '$'.number_format($d);
  53. }
  54. )
  55. );
  56. // SQL server connection information
  57. $sql_details = array(
  58. 'user' => '',
  59. 'pass' => '',
  60. 'db' => '',
  61. 'host' => ''
  62. );
  63. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  64. * If you just want to use the basic configuration for DataTables with PHP
  65. * server-side, there is no need to edit below this line.
  66. */
  67. require( 'ssp.class.php' );
  68. echo json_encode(
  69. SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
  70. );