Bring data from the table with where in codeigniter

0

Hello friends, it turns out that I have this information in the table:

and with CodeIgniter I need to bring all the data of id_servicio entered.

the code I have is this:

In the model:

 function getcoffeInfo ($id_servicio){
$this->db->select('*');
$this->db->where('id_servicio',$id_servicio);
$query = $this->db->get('Coffemovil');
return $query->row();
}

and in controller:

    public function getCoffeDate(){

    $new_id = $this->input->post('id_servicio');
    $this->load->model('Model_app');
    $data = $this->Model_app->getcoffeInfo($new_id);
    header('Content-Type: application/json');
    echo json_encode($data);
    }

The problem is that it only returns a single data and no more, I want all 54 for example!

What am I doing wrong? Greetings.

    
asked by Hernan Humaña 16.01.2017 в 21:57
source

2 answers

1

The problem is here:

function getcoffeInfo ($id_servicio){
   $this->db->select('*');
   $this->db->where('id_servicio',$id_servicio);
   $query = $this->db->get('Coffemovil');
   return $query->row();
}

on the line:

   return $query->row();

because you are returning just one row, it should look like this:

function getcoffeInfo ($id_servicio){
   $this->db->select('*');
   $this->db->where('id_servicio',$id_servicio);
   $query = $this->db->get('Coffemovil');
   return $query->result();
}

If you want to return a specific row (row 5 for example), use:

 return $query->row(5);

CodeIgniter Documentation

    
answered by 16.01.2017 / 22:19
source
1

with the command you use, you are only telling them to return you a single row ...

return $query->row();

If instead of using it better you use result? bone

return $query->result();

your code would look something like this ....

function getcoffeInfo ($id_servicio){
   $this->db->select('*');
   $this->db->where('id_servicio',$id_servicio);
   $query = $this->db->get('Coffemovil');
   return $query->result();
}
    
answered by 16.01.2017 в 22:45