Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. <?php
  2.  
  3. class Table extends CI_Controller
  4. {
  5.  
  6. function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->database();
  10. $this->load->helper('url');
  11. }
  12.  
  13. function index()
  14. {
  15. $this->load->view("table_view");
  16. }
  17.  
  18.  
  19. function ambil_data()
  20. {
  21.  
  22. //DASAR FONDASI DATA SERVER SIDE
  23. $draw=$_REQUEST['draw'];
  24. $length=$_REQUEST['length'];
  25. $start=$_REQUEST['start'];
  26. $search=$_REQUEST['search']["value"];
  27. $total=$this->db->count_all_results("Karyawan");
  28. $output=array();
  29. $output['draw']=$draw;
  30. $output['recordsTotal']=$output['recordsFiltered']=$total;
  31. $output['data']=array();
  32.  
  33. $requestData= $_REQUEST;
  34.  
  35.  
  36. //MENDEKLARASIKAN PENCARIAN BERDASARKAN ID
  37. $columns = array(
  38. 1 => 'NIP',
  39. 2 => 'NamaPegawai',
  40. 3 => 'NamaDepartemen'
  41. );
  42.  
  43.  
  44. $sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY NamaPegawai) as RowNum FROM Karyawan WHERE (NIP like '%%' ) ) a ";
  45.  
  46. $search_detail = "";
  47.  
  48. //UNTUK PENCARIAN DATA FIELD TERTENTU
  49. if( !empty($requestData['columns'][1]['search']['value']) )
  50. {
  51. $search_detail.=" AND NIP LIKE '".$requestData['columns'][1]['search']['value']."%' ";
  52. }
  53. if( !empty($requestData['columns'][2]['search']['value']) )
  54. {
  55. $search_detail.=" AND NamaPegawai LIKE '".$requestData['columns'][2]['search']['value']."%' ";
  56. }
  57. if( !empty($requestData['columns'][3]['search']['value']) )
  58. {
  59. $search_detail.=" AND NamaDepartemen LIKE '".$requestData['columns'][3]['search']['value']."%' ";
  60. }
  61.  
  62.  
  63.  
  64. $limit = " WHERE RowNum > ".$_REQUEST['start']." and RowNum <= ".$_REQUEST['length'];
  65. $order = " ORDER BY NamaPegawai ASC ";
  66.  
  67.  
  68. $query=$this->db->query($sql.$limit.$search_detail);
  69. //UNTUK MENCARI JUMLAH DATA KETIKA KONDISI PENCARIAN
  70. if($search!="")
  71. {
  72. $jum=$this->db->query($sql.$limit.$search_detail.$order);
  73. $output['recordsTotal']=$output['recordsFiltered']=$jum->num_rows();
  74. }
  75.  
  76. //LOOPING DATA
  77. $nomor_urut=$start+1;
  78. foreach ($query->result() as $desa)
  79. {
  80. $delete = "<a type='button' class='btn btn-primary' id='delete'>DELETE</button>";
  81. $edit = "<button type='button' class='btn btn-primary'>EDIT</button>";
  82.  
  83. $output['data'][]=array($nomor_urut ,$desa->NIP, $desa->NamaPegawai, $desa->NamaDepartemen );
  84. $nomor_urut++;
  85. }
  86.  
  87. echo json_encode($output);
  88.  
  89. }
  90.  
  91. }
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement