【发布时间】:2012-12-21 07:41:28
【问题描述】:
我在 codeigniter 中有一个用于列出的连接函数,但它只连接两个表,对于三个表我必须使用另一个函数等等有没有办法让这些函数对任何数量的连接都通用 型号代码
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);
}
【问题讨论】:
-
您可以将连接参数放在一个数组中,然后循环访问它们以在函数中访问它们吗?
-
你是否需要使用 Active Record 类强制编写查询......
-
感谢大家@Venkat 的回复实际上不是,但我的模型包含所有以活动内容编写的查询
-
没问题老兄。我在所有应用程序中都遵循正常的查询规则。
标签: php codeigniter activerecord join