How to put variable in a query? [duplicate]
the codeigniter way for your example is:
$data = $this->db->select('channel, MIN(product_name) as product_name, SUM(revenue) AS revenue') ->where('channel','chanel1') ->where('province',$area) ->group_by('SUBSTRING(product_name, 1, 3)') ->get('my_test_table') ->result();
Codeigniter Query Builder Class, it creates a query string, which escapes the columns properly
$data = $this->db->query('SELECT channel, MIN(product_name) as product_name, SUM(revenue) AS revenue FROM my_test_table WHERE channel = "chanel1" AND province='.$area.' GROUP BY SUBSTRING(product_name, 1, 3)')->result();
Note this solution probably is not secure. The variable can be SQL injected. I write the solution under your consideration.