Welcome Guest, Not a member yet? Register   Sign In
Inserting data in a column with condition
#1
Question 
(This post was last modified: 10-28-2016, 01:12 AM by Bright.)

When on of the admin clicks an approve button its supposed to add the user_id of the person approving to a field in approval table 

This is the button

 
Code:
   <?php echo anchor('admin/messages/approve/'.$message->id.'', 'Approve', 'class="btn btn-success"'); ?>


This is the approve function in Controller
Code:
    public function approve($id) {

    $data  = array(
      'first_approval' =>  $this->session->userdata('user_id')
     );


$this->Message_model->approve($id, $data);


//isset Message
$this->session->set_flashdata('success', 'Your approval was send');

//Redirect
redirect('admin/messages');

}

This is the approve method inside the Model
Code:
    public function approve($data) {

       $this->db->select('*');
       $this->db->from('approval');
       $this->db->join('messages', 'messages.id = approval.sms_id');

       $this->db->where('id', 'sms_id');
       $this->db->set('first_approval', $data);
       $this->db->update('approval');
    }

I have sms_id, first_approval, second_approval and third_approval columns in my approval table but for now I'm just testing if I can put session->user_id in the column 'first_approval'
Reply
#2

So what's your question?

and to save time... what's the error?
Reply
#3

(10-27-2016, 08:50 PM)enlivenapp Wrote: So what's your question?

and to save time... what's the error?

I have changed to this
Code:
  public function approve($id, $data) {
public function approve($id, $data) {
    $this->db->where('sms_id', $id);
    $this->db->update('approval',$data);
}

public function some_approve($id, $approval_data)
{
    $this->db->where('id', $id);
    $this->db->update('messages',$approval_data);
}
its working
Reply




Theme © iAndrew 2016 - Forum software by © MyBB