'How do I combine data from two tables and display them in a single column?

I have two views, repair and maintenance. both are a combination of three tables: repair, r_list, item; and maintenance, m_list, and item. I need to put the id of repair and the id of maintenance into a single column named ticket_id in a third table, tickets. So basically it should be like this: three tables plus three tables into one table combined

All three tables must exist simultaneously, meaning any change in repair should affect tickets, and the same thing with maintenance. I'm using CodeIgniter, and this is my code:

Model:

    public function get_tickets_view()
        {
            $this->db->select("
                tickets.id AS id,

                repair.repair_id AS ticket_id,
                maintenance.maintenance_id AS ticket_id,

                items.item_id AS item_id,

            ");
            
            $this->db->from("tickets");
            $this->db->join("items", "tickets.item_id = items.item_id", "left");
            $this->db->join("repair", "repair.item_id = tickets.item_id", "left");
            $this->db->join("maintenance", "maintenance.item_id = tickets.item_id", "left");


            $query = $this->db->get();
            return $query->result();
        }

Controller

    public function tickets()
        {
            $data['ticket'] = $this->sample_model->get_tickets_view();

            $data['main_content'] = 'page_address';
            $this->load->view('navbar', $data);

        }

Despite the page displaying properly, it refuses to actually pull the items inside either of those two table views. So what am I doing wrong?



Solution 1:[1]

You can combine arrays with

<?php $animals = array( "monkey","fish","ape"); $humans = array("Jim","Bob", "Josh");

array_merge($animals,$humans); 
?>

There are tons of array functions here:

https://www.w3schools.com/php/php_ref_array.asp

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Taj Irwin-Wells