Welcome Guest, Not a member yet? Register   Sign In
Datatable delete record not working properly
#1

(This post was last modified: 11-11-2022, 01:00 AM by SnowranCruzick.)

I used datatables to show my MySQL data in Codeigniter framework. I want to delete specific records in the table. Used the following code fragments.

<th>Action</th>

    <?php
    foreach ($selectedDataData as $imprestReqData) {
        foreach ($imprestReqData as $value) {
                                                    $delete_link = anchor('fees/deletePayment/' . $value->payback_id, '<i class="fa fa-trash-o"></i> ' . 'Delete', 'class="s_edit"');
                                                $action = '<div class="text-center"><div class="btn-group text-left">'
                                                    . '<button type="button" class="btn btn-danger btn-xs btn-info dropdown-toggle" data-toggle="dropdown">Actions<span class="caret"></span></button><ul class="dropdown-menu pull-right" role="menu"><li>' . $delete_link . '</li></ul>';
    ?>



    <td><input class="selected" type="checkbox" name="selected[]" value="<?= $value->payback_id ?>" /></td>
    }
Controller
public function deletePayment($id)
        {
            $message = "Error Occured.";
            $data = $this->Fees_model->getFeesPayBack($id);
            if (!empty($data)) {
                $data = (array) $data[0];
                $data['status'] = "Deleted";
                $result = $this->Fees_model->regFeesTransfer($data);
                $message = $result == $data['id'] ? "Record Deleted Successfully." : "Error Occured.";
            } else {
                $message = "No Data Found.";
            }
            $this->session->set_flashdata('message', $message);
            redirect('fees/collectionList/');
        }
                                 
Model
function regFeesTransfer($data)
        {
            if ($data["id"] === "" || $data["id"] === 0) {
                $data['created_at'] = date("Y-m-d H:iConfused");
                $data['created_by'] = $this->session->userdata("id_user");
                // dd($data);
                $this->db->insert('fees_payback', $data);
                if ($this->db->affected_rows()) {
                    //user activity////////////////
                    $id = $this->db->insert_id();
                    return $id;
                }
                return false;
            } else {
                $data['updated_at'] = date("Y-m-d H:iConfused");
                $data['updated_by'] = $this->session->userdata("id_user");
                $this->db->update('fees_payback', $data, array('id' => $data["id"]));
                if ($this->db->affected_rows()) {
                    return $data["id"];
                }
                return false;
            }
        }
Output
The code is working farely. Sometimes delete records while some records are echatspin echatrandom not. What may be going wrong ? Can anyone help ?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB