0

I am working on one jquery script with codeigniter. i get dynamic data in for loop. i want to add crud operations on it. but My view and Edit is working fine.But dont know how to add delete method on it.

for(var j=0;j<arrayData.length;j++)
    {
          var country = "";
          var color = "";
          action1 = "VIEW";
          action2 = "EDIT";
          action3 = "DELETE";


            if(arrayData[j].key=="40")
             {
                 country = "UK";                              
                 color = "INDIANRED";
                 check+= '<a class="btn btn-success"  style="background-color : ' + color  + ';" href="<?php echo base_url()?>responsible/uk_pdf/'+arrayData[j].value+'">'+action1+
                              '</a> '+
                                '<a class="btn btn-success"  style="background-color : ' + color  + ';" href="<?php echo base_url()?>responsible/edit_slips_uk/'+arrayData[j].value+'">'+action2 +
                              '</a> ' + '<a class="btn btn-success"  data-toggle="modal" style="background-color : ' + color  + ';" href="<?php echo base_url()?>responsible/delete_slips_uk/'+arrayData[j].value+'">'+action3 +
                              '</a> | ';                                      

             }              

    }

arrayData[j].value in this i am getting my value.responsible/delete_slips_uk I am calling this method to delete my row. Controller:

public function delete_slips_uk()
  {

    $this->load->model('pay_slips_model');
    $result=$this->pay_slips_model->delete_slips_uk($id);        
    if($result==true)
      {
        $this->session->set_flashdata('success_msg',"Deleted Successfully");
        redirect('responsible/view_slips_admin_1');
      }
    else
      {
        $this->session->set_flashdata('error_msg',"Customer Records Deletion Failed");
        redirect('responsible/view_slips_admin_1');
      }

  }

Model:

public function delete_slips_uk($id)
                {

                    $this->db->where('id', $id);                   
                    $this->db->delete('uk_new_salary_slip');
                    return ($this->db->affected_rows() != 1 ) ? false:true;
                }

I am stuck on delete function. onclick delete it goes to my method it directly goes to else condition with this message Customer Records Deletion Failed.I am unable to call post my arrayData[j].value from jquery to my controller. please help me with the same. so i can manage to complete my delete operations too.

2
  • Use ajax functions. Commented Feb 27, 2018 at 8:42
  • Try doing print_r to the $result variable in your delete_slips_uk() method. Commented Feb 27, 2018 at 8:45

1 Answer 1

2

$result=$this->pay_slips_model->delete_slips_uk($id); expects an $id but none is passed causing delete_slips_uk to invariably return false.

Revised controller function:

public function delete_slips_uk($id=null)
  {

    if (is_null($id)) {
        $this->session->set_flashdata('error_msg',"Missing id!");
        redirect('responsible/view_slips_admin_1');
    }

    $this->load->model('pay_slips_model');
    $result=$this->pay_slips_model->delete_slips_uk($id);        
    if($result==true)
      {
        $this->session->set_flashdata('success_msg',"Deleted Successfully");
        redirect('responsible/view_slips_admin_1');
      }
    else
      {
        $this->session->set_flashdata('error_msg',"Customer Records Deletion Failed");
        redirect('responsible/view_slips_admin_1');
      }

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

1 Comment

No problem! In the future you should develop with error reporting on as it would have given you a notice that the variable was missing. Also general troubleshooting suggests that you always check your inputs and outputs at various points ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.