optimized sql in codeigniter
// getData Optimized
public function getData($table, $cond = '', $field = '', $orderby = '', $limit = '', $join = '')
{
if ($field == '') {
$field = '*';
}
$this->db->select($field);
$this->db->from($table);
if (is_array($join) && count($join) > 0) {
foreach ($join as $k => $v) {
$this->db->join($v['table'], $v['condition'], $v['type']);
}
}
if ($cond != '') {
$this->db->where($cond);
}
if ($orderby != '') {
$this->db->order_by($orderby['0'], $orderby['1']);
}
if ($limit != '') {
$this->db->limit($limit);
}
$result = $this->db->get()->result();
return $result;
}