2

i want to update my array data from table monitordata, but the data wont update i dont know where's the problem. there's no error in this code too :(

this is my controller

public function ubah($id) {


    $data_lama = $this->monitor_m->get($id); 
    $this->data->tglmonitor = $data_lama->tglmonitor;

    $this->data->detail = $this->monitor_m->get_record(array('monitor_data.idMonitor'=>$id),true);


    $this->template->set_judul('SMIB | Monitoring')
         ->render('monitor_edit',$this->data);  
}

public function ubahku($id) {
    $id = $this->input->post('idMonitor_data'); 

    if($this->input->post('idinven')!=NULL){
            $idMonitor = $this->input->post('idMonitor');
            $kondisi = $this->input->post('kondisi');
            $nobrg = $this->input->post('nobrg');
            $keterangan = $this->input->post('keterangan');
            $kdinven = $this->input->post('kdinven');
            $idinven = $_POST['idinven'];

            for($i = 0; $i < count($idinven); $i++){

            $data_detail = array( 
                        'idMonitor' => $this->input->post('idMonitor'),
                        'idinven'=> $idinven[$i],
                        'kdinven'=> $kdinven[$i],
                        'nobrg'=> $nobrg[$i],
                        'kondisi'=> $kondisi[$i],
                        'keterangan' => $keterangan[$i]);
            //print_r($data_detail);
            $where = array('idMonitor_data' => $id);
            $this->monitordata_m->update_by($where,$data_detail);

            }
        }                  redirect('monitorcoba');  
}

This is my model monitordata_m

class Monitordata_m extends MY_Model {

public function __construct(){
    parent::__construct();
    parent::set_table('monitor_data','idMonitor_data');
}

This is MY_Model model i put in core folder.

public function update_by($where = array(), $data = array()) {
    $this->db->where($where);
    if ($this->db->update($this->table,$data)){
        return true;
    }
    return false;
}

And this is my view

<?php echo form_open(site_url("monitorcoba/ubahku"),'data-ajax="false"'); ?>
<input data-theme="e" style="float: right;" data-mini="true" data-inline="false" data-icon="check" data-iconpos="right" value="Simpan" type="submit" />

<div data-role="collapsible-set" data-mini="true">
<?php foreach ($detail as $items): ?>    
<div data-role="collapsible">
<?php echo form_hidden('idMonitor_data', $items['idMonitor_data'] ); ?>

<?php echo form_hidden('idMonitor', $items['idMonitor'] ); ?>
    <h4><?php echo '[ '.$items['kdinven'].' ] '.$items['namabrg'] ?> </h4>
    <?php echo form_hidden('kdinven', $items['kdinven'] ); ?>
   <?php echo form_hidden('idinven', $items['idinven'] ); ?>     
    <div data-role="controlgroup">
    <?php echo form_label ('Kondisi : ');
        echo " <select name='kondisi' data-mini='true'>

 <option value=".$items['kondisi'].">".$items['kondisi']."</option>
                    <option value=''>--Pilih--</option>
                    <option value='Baik'>Baik</option>
                    <option value='Rusak'>Rusak</option>
                    <option value='Hilang'>Hilang</option>";    
              echo "</select>";



          echo form_input('keterangan',@$keterangan,'placeholder="Masukan Keterangan Tambahan"','class="input-text"');
 ?>         
   <?php echo form_close(); ?>

even if i use update_by it doesnt work. it's been 2 weeks and i have no clue :( i've tried all of the answer that i found in google but still.. so please help me.

This is my Database profiler result

This is the DATABASE result and POST_DATA for method ubahku This is the database result for method ubahkuAnd this is Post_data result

13
  • Have you tried enabling the profiler so that you can see what SQL statements are being run? Commented Nov 6, 2016 at 22:33
  • @colonelclick yes i have. but i dont know what's wrong because i cant understand the report ._. sorry Commented Nov 7, 2016 at 8:43
  • first debug the flow. print value of id in controller and then in model check its value if is it correct or not Commented Nov 7, 2016 at 10:47
  • 1
    Can you add the output from the Database section of the profiler? Commented Nov 7, 2016 at 16:59
  • 1
    There must be more code that we do not see. In your update SQL we can see the first argument tries to set idMonitor_data = 48, but we do not see that in your PHP anywhere. We also see that your function ubahku expects an id parameter in the URL but your form does not seem to be passing one and this should show an error. Is this the current code you are showing us? Commented Nov 9, 2016 at 15:38

3 Answers 3

1

You have defined a method named update_by, but you are calling $this->monitordata_m->update($id,$data_detail);. Definitely it should not work. please call $this->monitordata_m->update_by($id,$data_detail); from your controller & check what will happen.

Sign up to request clarification or add additional context in comments.

Comments

1

Firstly, Please correction $this->monitordata_m->update($id,$data_detail); to $this->monitordata_m->update_by($id,$data_detail); because your function name is update_by in your monitordata_m model.

Secondly, in your monitordata_m model update_by function have 2 param like $where = array() $data = array(), $where is a array but you calling in controller only $id. Your $id is not array. $where is like that $where = array('id' => $id) //id is where field name from db table

So, ubahku($id) method in your controller call $where in update_by function:

$where = array('id' => $id); // 'id' means "where field name"
$this->monitordata_m->update_by($where,$data_detail);

8 Comments

still not working, i know its weird. but when i use update_by function in another function in controller it works fine.
i saw your html form. you have used form action monitorcoba/coba. your controller name is monitorcoba and method name is coba. Right?
and you have used a condition in ubahku method your controller if($this->input->post('idinven')!=NULL){. Tell me please where your idinven field in your html form?
sorry that's my typo it should be monitorcoba/ubahku. oh my god thank you so much i forgot too add idinvenin my html form.
Now it works, but after i added it, i have another problem, i'm trying too update data for data 1(which is the first one) but the result is data 1 didnt changed, its data 5 (which is the last data) that did changed its weird. i'm trying to update data 1 not data 5. :(
|
0

So, thank you so much for everyone who answer my question. so the problem was when i update the data, system only detect "kondisi[]" and "keterangan[]" as an array because i use this "[]" for both of it, so i just have to add "[]" in the end of every name in html form / views. so system will detect every input as an array. i hope you understand what i'm saying, sorry for my bad english. thank you this case is closed :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.