Concat in php codeigniter

Please help me understand the correct join syntax.

I have a table called inventory that has:

trans_id    
trans_items items -> item_id         
trans_user  employees -> person_id           
trans_date                   
trans_comment                
trans_inventory     

As you can see above, trans_items is the foreign key in the element table, and trans_user is the foreign key in the employee table, and the employee identifier is the foreign key for the people table.

Now what I want to do is display the inventory table in the HTML, but instead of displaying the employee ID, I want the employee ID to be displayed.


EDIT ................................................ therefore I was turned on to display only the last employee name using this code:

$this->db->select('inventory.*, items.name ,people.last_name');
$this->db->from('inventory');
$this->db->join('items', 'inventory.trans_items = items.item_id' , 'left');
$this->db->join('people', 'inventory.trans_user = people.person_id' , 'left');
$this->db->where('deleted', 0);
$this->db->order_by('trans_date desc');

with model code:

foreach($report_data as $row)
        {
            $tabular_data[] = array($row['name'], $row['last_name'],$row['trans_date'], $row['trans_inventory'], $row['trans_comment']);
        }

but I need this first and last name, so I did this:

$this->db->select('inventory.*, items.name ,CONCAT(people.first_name, " ",people.last_name) as employee');
$this->db->from('inventory');
$this->db->join('items', 'inventory.trans_items = items.item_id' , 'left');
$this->db->join('people', 'inventory.trans_user = people.person_id' , 'left');
$this->db->where('deleted', 0);
$this->db->order_by('trans_date desc');

with model code:

foreach($report_data as $row)
        {
            $tabular_data[] = array($row['name'], $row['employee'],$row['trans_date'], $row['trans_inventory'], $row['trans_comment']);
        }

, concat. , .

+3
2

( $this- > db- > select ('your select part', FALSE):

$this->db->select('inventory.*, items.name ,CONCAT(people.first_name, " ",people.last_name) as employee', FALSE);
$this->db->from('inventory');
$this->db->join('items', 'inventory.trans_items = items.item_id' , 'left');
$this->db->join('people', 'inventory.trans_user = people.person_id' , 'left');
$this->db->where('deleted', 0);
$this->db->order_by('trans_date desc');

Codeigniter:

FALSE, CodeIgniter . , .

+21
$query=$this->db->select("id, CONCAT(nombre,".' '.",apellido_paterno) as nombre", false)->
                                from("empleado")->
                                where('empleado', $filtro)->
                                order_by("nombre")->
                                get();

false,

0

Source: https://habr.com/ru/post/1784041/


All Articles