Advertisement
yhoezt_27

Untitled

Mar 5th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. CONTOH EDIT COMBOBOX (CI Framework)
  2.  
  3. HTML
  4. echo form_dropdown("subktgr",$subktgr,"",'id="id_subktgr" class="form-control"');
  5.  
  6. JQUERY/AJAX
  7. function edit(id)
  8. {
  9. $('#form')[0].reset();
  10. $.ajax({
  11. url : "<?php echo site_url('ktgr_brng/ajax_edit/')?>/" + id,
  12. type: "GET",
  13. dataType: "JSON",
  14. success: function(data)
  15. {
  16. method = 'ubah';
  17. url = '<?php echo site_url('ktgr_brng/proses_edit')?>';
  18. $('[name="id_ktgr_brng"]').val(data.id_ktgr_brng);
  19. $('[name="ktgr_brng"]').val(data.ktgr_brng).attr("readonly","readonly");
  20. $('[name="subktgr"]').val(data.sub).change();
  21. $('[name="keterangan"]').text(data.keterangan);
  22. $('#form-modal').modal('show');
  23. $('.modal-title').text('Form Edit Data');
  24. tampil_itemasset();
  25. },
  26. error: function (jqXHR, textStatus, errorThrown)
  27. {
  28. alert('Error get data from ajax');
  29. }
  30. });
  31. }
  32.  
  33. PHP (LOGIC)
  34. function ajax_edit($id)
  35. {
  36. $data = $this->m_all->get_by_id($this->table, $this->primary, $id);
  37. echo json_encode($data);
  38. }
  39.  
  40. PHP (QUERY)
  41. function get_by_id($table, $id_table, $id)
  42. {
  43. $this->db->select('*');
  44. $this->db->from($table);
  45. $this->db->where($id_table, $id);
  46. $q = $this->db->get();
  47. return $q->row();
  48. }
  49.  
  50. DESIGN TABLE (Dalam konteks kasus ini/contoh)
  51. id_ktgr_brng ktgr_brng sub keterangan
  52. 1 Jas hujan 0 Kategori jas hujan
  53. 2 lampu 0 kategori lampu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement