Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Update closed column in database using button click?

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 202
    Answer it

    I've been trying to do this multiple times but still didn't get the answer. I have a column named closed in my database and close button in my view, whenever I click the button close, I want it to update my closed column to '0' if it is closed and '1' if it still open. below is my code in the controller, sorry I'm still new to this. 

    Public function close(){
          $pvar = array();
          $pid = $this->uri->segment(1, 0);
          $iid = $this->uri->segment(2, 0);
          $pageisx = $this->uri->segment(3, 0);
          $pagei = 'Purchase Order';
          $iuser = $this->users->chkadmin();
          $gpost = $this->input->post(NULL, TRUE);
          $pvar['pageimenu'] = 'purchasing';
          $pvar['htitle'] = 'Purchase: '.$iid;
          $this->db->select('*');
          $this->db->from('po');
          $this->db->where('po.pono', $iid);
          $this->db->order_by('po.pono', 'DESC');
          $pvar['purchaseorder'] = $this->db->get()->row_array();
          if (isset($gpost['close']))
          {
            if (isset($gpost['locode'])) {
              $getlo = $gpost['locode'];
              if ($getlo == $this->session->skey) {
                foreach ($gpost['close'] as $k => $x) {
                  $close = 1;
                  $c['closed'] = $close;
                  //$close = $this->input->post('1');
                    $this->db->set('closed', 1 );
                    $this->db->where('po.id', $k);
                    $this->db->update('po');
                  }
            redirect(base_url().'purchaseorderlist.php');
          }}}
            $pvar['css'] = '
            <link href="'.base_url().'css/manage.css" rel="stylesheet" type="text/css" />
          ';
          $pvar['pc'] = $this->load->view('purchasing/purchaseorderview', $pvar, TRUE);
          $this->load->view('home', $pvar);
          }

     

 1 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: