I am trying to filter data from database by adding a variable into the query. The query that I have made is like this:
$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();
But it result in this message:
Error Number: 1054
Unknown column '$area' in 'where clause'
I use the "$area" variable in the query to make it dynamically filter the data based on the input from the user. So the $area is a variable that assign any value from the input.