Multiple Joins in Codeigniter

前端 未结 4 1946
孤独总比滥情好
孤独总比滥情好 2020-12-08 23:33

I\'m new to building databases and I\'m trying to do a JOIN based on a having three database tables.

Table A = ID, Name, etc
Table B = ID, Name, etc
Table C          


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 00:13

    if you want a flexible query you could use:

    http://codeigniter.com/user_guide/database/results.html

    which utilizes the following syntax $query = $this->db->query('SELECT * FROM my_table');

    here is the query:

    SELECT a.name as namea ,b.name as nameb FROM tablec c
    JOIN tablea a ON a.ID = c.ID
    JOIN tableb b ON b.ID = c.ID
    

    you may want to read more about joins here

    then go through your results in such a way:

    $query = $this->db->query("YOUR QUERY");

    foreach ($query->result_array() as $row)
    {
       echo $row['namea'];
       echo $row['nameb'];
    }
    

提交回复
热议问题