1

リスト用にcodeigniterに結合関数が1つありますが、結合するのは2つのテーブルのみです。3つのテーブルの場合、別の関数を使用する必要があります。これらの関数を任意の数の結合に共通にする方法はありますか モデルコード

public function __construct()
{
    $this->load->database();
}

//listing with join for two tabels
public function get_joinlist($table,$value,$table2,$condi,$join_type,$order_by,$order,$where,$limit, $offset)
{
        $this->db->select($value);
            $this->db->join($table2,$condi,$join_type);
    $this->db->order_by($order_by,$order);
    $this->db->where($where);
    return $query= $this->db->get($table, $limit, $offset);
}
//listing with join for three tabels
public function get_joinlist1($table,$value,$table2,$condi1,$join_type1,$table3,$condi2,$join_type2,$where,$order_by,$order)
{
    $this->db->select($value);
    $this->db->join($table2, $condi1,$join_type1);
    $this->db->join($table3, $condi2,$join_type2);
    $this->db->where($where);
    $this->db->order_by($order_by,$order);
    return $this->db->get($table);
}
4

1 に答える 1

2

これは、開始するための非常に簡単な例です

$joins配列として構築:

$joins = array(
    array(
        'table' => 'table2',
        'condition' => 'table2.id = table1.id',
        'jointype' => 'LEFT'
    ),
);

結合を配列として処理する関数の例:

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();
}
于 2012-12-21T08:54:29.190 に答える