dimanche 21 janvier 2018

how to update multple rows checkbox with one button

hey guys can you guys help me with this checkbox problem, i want if i check the coloumn and press update update it will update at current time

this is an example

I want if I check the checkbox and press the update button and the coloumn will update at the current time

this is my view :

<div class="container">      
  <div class="row">
    <div class="col-md-10">
      <div class="panel panel-info">
        <div class="panel-heading">Setting Jam & Tanggal Mesin</div>
        <div class="panel-body">
              <table id="devid_auto" class="table table-bordered dt-responsive" cellspacing="0" width="100%">
                <thead>
                  <tr>
                    <th width="1%" align="center"><input type="checkbox" onClick="toggle(this)" id="checkAll" name="checkAll" /></th>
                    <th width="10%" align="center">Nama Mesin</th>
                    <th width="5%" align="center">IP Address</th>
                    <th width="10%" align="center">SN</th>
                    <th width="5%" align="center">Ethernet Port</th>
                    <th width="10%" align="center">Last Update</th>
                  </tr>
                </thead>
                <tbody>
                <?php 

                foreach($data as $d){

                ?>
                  <tr>
                    <td><input class="childbox" type="checkbox" name="msg[]" id="id" value="<?php echo $d['devid_auto'] ?>" /></td>
                    <td class="data-check"  ><?php echo $d['device_name']; ?></td>
                    <td class="data-check"  ><?php echo $d['ip_address']; ?></td>
                    <td class="data-check"  ><?php echo $d['sn']; ?></td>
                    <td class="data-check"  ><?php echo $d['ethernet_port']; ?></td>
                    <td class="data-check"  ><?php echo $d['lastupdate_date']; ?></td>
                  </tr>
                <?php } ?>
                </tbody>                    
              </table>

              <div class="form-group">
                <label for="colFormLabelLg" class="col-sm-3 col-form-label col-form-label-lg">Tanggal & Waktu Sekarang</label>
                <div class="col-sm-3">
                  <input type="" class="form-control" id="" value="<?php date_default_timezone_set("Asia/Jakarta"); echo date(" d/m/Y h:i:s ");?>""  readonly>
                </div>  
              </div>
        </div>
        <div class="panel-footer text-right">
          <button allign="center" class="btn btn-danger" onclick="update()">Update Date and time</button>
        </div>
      </div>
    </div><!-- end cols-->
  </div><!--end row-->
</div> <!-- end container-->   

this is my script :

<script type="text/javascript">
          function update(id)
        {
            var list_id = [];
            $("#id:checked").each(function() {
                    list_id.push(parseInt(this.value));
            });
        console.info(JSON.stringify(list_id));

            if(list_id.length > 0)
            {
                if(confirm('Are you sure update this '+list_id.length+' data?'))
                {
                    $.ajax({
                        type: 'POST',
                        data: {'devid_auto': list_id},
                        url: '<?php echo site_url('setting/mesin_update')?>',
                        success: function(result)
                        {
                            console.info("isine console data : "+result.replace(/\s/g,''));
                            var hasil = result.replace(/\s/g,'');
                            if(hasil == 'y')
                            {
                              alert("Success");
                              location.reload();
                            }
                            else
                            {
                                alert('Failed.');
                            }

                        },
                        error: function (jqXHR, textStatus, errorThrown)
                        {
                            alert('Error updating data');
                        }
                    });
                }
            }
            else
            {
                alert('no data selected');
            }

        }
            </script>

and this is my controller :

public function mesin_update()
    {
        $initiated_date =  date('Y-m-d H:i:s');
        $data = array(
                'lastupdate_date' => $initiated_date,
            );
        $this->Jam_tgl_model->jam_tanggal_update(array('devid_auto' => $this->input->post('devid_auto')), $data);
        echo json_encode(array("status" => TRUE));
    }

and this is my model :

public function jam_tanggal_update($where, $data)
{
    $this->db->update($this->table_dept, $data, $where);
    return $this->db->affected_rows();
}

I have tried it with my code but nothing has changed on coloumn last update date

please help fix my code so i can finish it




Aucun commentaire:

Enregistrer un commentaire