Select record to record in query Codigneter

0

I am new to this of the Codeigneter so I apologize beforehand:

I have the following Query defined:

$query=$this->db->select('articulo,descripcion,precio,cant,por_dto1,imp_cos,imp_bru,imp_net');
    $query=$this->db->from('alb_lin'); 
    $query=$this->db->where('empresa',$empresa);        
    $query=$this->db->where('delegacio',$delegacio);
    $query=$this->db->where('ser_alb',$ser_alb);
    $query=$this->db->where('num_alb',$num_alb);
    $query=$this->db->get('');        
    $data["DatosLinea"]=array();

    if($query->num_rows()>0)
    {
      foreach ($query->result() as $fila)
      {            
        $data["DatosLinea"]["articulo"] = $fila->articulo;            
        $data["DatosLinea"]["descripcion"] = $fila->descripcion;
        $data["DatosLinea"]["precio"] = $fila->precio;
        $data["DatosLinea"]["cant"] = $fila->cant;
        $data["DatosLinea"]["por_dto1"] = $fila->por_dto1;
        $data["DatosLinea"]["imp_cos"] = $fila->imp_cos;
        $data["DatosLinea"]["imp_bru"] = $fila->imp_bru;
        $data["DatosLinea"]["imp_net"] = $fila->imp_net;
      }
      return $data["DatosLinea"];
    }

Now, this query returns more than one record, but I do not know how to indicate in the view that it shows them one by one since I have put the following

    $html = (" ".$VerLinea['articulo']." ");

and it only shows me the last one. Can you help me?

Thanks

    
asked by Raül Marínez i Campos 05.07.2018 в 14:11
source

3 answers

0

Thank you very much for the help but it does not work for me, it gives me the following error:

Severity: Notice

Message: Trying to get property of non-object

On the other hand, the view is coded as follows:

    $DatosLinea = $this->input->post('DatosLinea');        
    $VerLinea = $this->pdfs_model->getLineasSeleccionadas($empresa, $delegacio, $num_alb, $ser_alb);        

    foreach ($VerLinea as $fila)         
    {
        $articulo       = $VerLinea['articulo'];
        $descripcion    = $VerLinea['descripcion'];
        $cant           = $VerLinea['cant'];
        $por_dto1       = $VerLinea['por_dto1'];   
        $imp_cos        = $VerLinea['imp_cos'];   
        $imp_bru        = $VerLinea['imp_bru']; 
        $imp_net        = $VerLinea['imp_net']; 
    }

And what I mention so much when doing the ECHO I get all the records and if I get it out by HTML as I have indicated before, I only get the last one.

    
answered by 05.07.2018 в 18:35
0

I imagine that your Controller should look like this.

    $this->db->select('articulo,descripcion,precio,cant,por_dto1,imp_cos,imp_bru,imp_net');
        //$this->db->from('alb_lin'); 
        $$this->db->where('empresa',$empresa);        
        $this->db->where('delegacio',$delegacio);
        $this->db->where('ser_alb',$ser_alb);
        $this->db->where('num_alb',$num_alb);
        $query = $this->db->get('alb_lin');    
        $data['DatosLinea'] =$query->result();
        $this->load->view('index',$data);

Put something like that in the view.

<?php if ($DatosLinea): ?>
  <?php foreach ($DatosLinea as $key): ?>
   <?php echo $key->articulo ?>
  <?php endforeach; ?>
<?php endif; ?>
    
answered by 05.07.2018 в 17:42
0

Hello you have to check your model well or if you do not send it, but I give you some guidelines.

Model

public function getLineasSeleccionadas($empresa, $delegacio, $num_alb, $ser_alb){
....
return $resultados->result();
}

In your case you should use result () maybe you are returning with

return $resultado->row();

The latter gives you only one registration line

    
answered by 24.07.2018 в 18:57