简体   繁体   中英

How to INNER JOIN an array?

How can I INNER JOIN an array in codeigniter?

I've got two tables, Element and Data:

TABLE ELEMENT

id |   name   | data
----------------------
1  |  product | 1,5,4

TABLE DATA

id |   name
---------------
1  |  data 1
2  |  data 2
3  |  data 3
4  |  data 4
5  |  data 5
6  |  data 6

This is my function:

function get($id)
    {
        $this->db->select('
            element.*,
            data.name data_name'
        );

        $this->db->from('elements as element');

        $this->db->join('data_element as data', 'data_name.id = element.data', 'left');

        $this->db->where('id', $id);

        $query = $this->db->get();
        if($query->num_rows() > 0){
            return $query->result();
        } else {
            return 0;
        }
    }

But this return only the first result data 1 (in this case) from TABLE ELEMENT column data .

Is it possible combine array with inner join?

我已经用GROUP_CONCAT(data_element.id) as data_element_id解决了它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM