concatenate three fields in listbox

0

I tried to show the list of users in a listbox, but I have not managed to make it work. If I just want to show a field like the name, it works fine, but I need to show the name and the two surnames.

<?php


 class mHorarios extends CI_Model
 {

 function __construct()
 {
  parent::__construct();
 }

 public function lista_usuarios (){

 $this->db->select('CONCAT( pnombre, '.', apellido_pa , '.', apellido_ma) AS nombre');
 $this->db->order_by('nombre', 'asc');
 $usuarios = $this->db->get('usuarios');



if($usuarios->num_rows() > 0){

      return $usuarios->result();
    }
  }
 }

 ?>

I get the following error

  

A PHP Error was encountered

     

Severity: Notice Message: Undefined property: stdClass :: $ rut_usu   Filename: users / vAdminister_Horarios.php Line Number: 73   Backtrace: File:   C: \ xampp \ htdocs \ SAE \ application \ views \ users \ vAdministrar_Horarios.php   Line: 73 Function: _error_handler File:   C: \ xampp \ htdocs \ SAE \ application \ controllers \ cHorarios.php

     

A PHP Error was encountered

     

Severity: Notice Message: Undefined property: stdClass :: $ pname   Filename: users / vAdminister_Horarios.php Line Number: 73   Backtrace:

    
asked by CristianOx21 12.09.2017 в 14:35
source

1 answer

0

You should not complicate when making queries in the models, better place directly the query you need:

function lista_usuarios(){
    $sql="SELECT concat_ws(' ',pnombre, apellido_pa ,apellido_ma) as nombre
    from usuarios order by nombre asc";
    $consulta = $this->db->query($sql);
    return $consulta->result_array();
}

The concat_ws gets your data concatenated with the first value in the middle of the rest. I hope it's helpful, greetings.

    
answered by 28.03.2018 в 16:53