Tuesday 3 November 2015

Common join function in codeigniter for listing

Here's a very simple example to get you started
Construct $joins as array:

$joins = array(
    array(
        'table' => 'table2',
        'condition' => 'table2.id = table1.id',
        'jointype' => 'LEFT'
    ),
);
Example function handling joins as an array:
 public function get_joins($table, $columns, $joins)
{
    $this->db->select($columns)->from($table);
    if (is_array($joins) && count($joins) > 0)
    {
        foreach($joins as $k => $v)
        {
            $this->db->join($v['table'], $v['condition'], $v['jointype']);
        }
    }
    return $this->db->get()->result_array();
}

1 comment:

  1. Get Laravel development Solutions from the Best Laravel Development Company in India & USA. We provide industry-wise web Solutions like Health, Pharma, Realstate, IT, etc. Contact us : +91-9806724185 or Contact@expresstechsoftwares.com

    ReplyDelete

Simple CRUD in Laravel Framework

Creating, reading, updating, and deleting resources is used in pretty much every application. Laravel helps make the process easy using re...