Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CONTOH EDIT COMBOBOX (CI Framework)
- HTML
- echo form_dropdown("subktgr",$subktgr,"",'id="id_subktgr" class="form-control"');
- JQUERY/AJAX
- function edit(id)
- {
- $('#form')[0].reset();
- $.ajax({
- url : "<?php echo site_url('ktgr_brng/ajax_edit/')?>/" + id,
- type: "GET",
- dataType: "JSON",
- success: function(data)
- {
- method = 'ubah';
- url = '<?php echo site_url('ktgr_brng/proses_edit')?>';
- $('[name="id_ktgr_brng"]').val(data.id_ktgr_brng);
- $('[name="ktgr_brng"]').val(data.ktgr_brng).attr("readonly","readonly");
- $('[name="subktgr"]').val(data.sub).change();
- $('[name="keterangan"]').text(data.keterangan);
- $('#form-modal').modal('show');
- $('.modal-title').text('Form Edit Data');
- tampil_itemasset();
- },
- error: function (jqXHR, textStatus, errorThrown)
- {
- alert('Error get data from ajax');
- }
- });
- }
- PHP (LOGIC)
- function ajax_edit($id)
- {
- $data = $this->m_all->get_by_id($this->table, $this->primary, $id);
- echo json_encode($data);
- }
- PHP (QUERY)
- function get_by_id($table, $id_table, $id)
- {
- $this->db->select('*');
- $this->db->from($table);
- $this->db->where($id_table, $id);
- $q = $this->db->get();
- return $q->row();
- }
- DESIGN TABLE (Dalam konteks kasus ini/contoh)
- id_ktgr_brng ktgr_brng sub keterangan
- 1 Jas hujan 0 Kategori jas hujan
- 2 lampu 0 kategori lampu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement