How to get the length of a column in Codeigniter?

0

Hi, I'm working on Code Igniter from php and I need to multiply the number I send from the front with the total data in a column lenght it has the name id and is auto incretable.

try this, from model:

function InsertRegistro($data){

$this->db->insert('mascalo',$data);
$this->db->select_max('id');
$query = $this->db->get('mascalo');
return $query->row();

}

and from the controller:

public function getdatoCHILE(){

$data = array(
'total' => $this->input->post('total'),
'hash' => $this->input->post('hash')
);

$this->load->model('Model_app');
$largo = $this->Model_app->InsertRegistro($data);

if ($data==null) {
  $this->_app_output($this->error);  
}

else {
        $dinero= $data['total'];
        $numero = $largo * $dinero

  header('Content-Type: application/json');
  echo json_encode($numero);
}

}

Help please! Greet me once again.

    
asked by Hernan Humaña 01.02.2017 в 14:21
source

1 answer

1

The problem comes from the side that $ query-> g (); does not return the maximum id if you do not select the field, try this:

function InsertRegistro($data){
    $this->db->insert('mascalo',$data);
    $this->db->select_max('id as largo');
    $query = $this->db->get('mascalo');
    $row = $query->row(); 
    return $row->largo;}
    
answered by 01.02.2017 в 15:42