optimized sql in codeigniter

Solutions on MaxInterview for optimized sql in codeigniter by the best coders in the world

showing results for - "optimized sql in codeigniter"
Deacon
26 Jul 2019
1// getData Optimized
2    public function getData($table, $cond = '', $field = '', $orderby = '', $limit = '', $join = '')
3    { 
4        if ($field == '') {
5            $field = '*';
6        }
7
8        $this->db->select($field);
9        $this->db->from($table); 
10
11        if (is_array($join) && count($join) > 0) {
12             foreach ($join as $k => $v) {
13                $this->db->join($v['table'], $v['condition'], $v['type']);
14             }
15        }
16
17        if ($cond != '') {
18            $this->db->where($cond);
19        }
20
21        if ($orderby != '') {  
22            $this->db->order_by($orderby['0'], $orderby['1']);
23        }  
24
25        if ($limit != '') {  
26            $this->db->limit($limit);
27        }  
28
29        $result = $this->db->get()->result();
30        return $result;
31    } 
32