Q:

CodeIgniter query error

I am using codeIgniter and am really stucked on it.
Here's my model function
public function get_products_names($c_name)
{

$this->db->query('SELECT name
                  FROM products
                  WHERE category=$c_name');

return $query->result_array();
}   

And I'm calling this function from the controller class as follows
    $this->load->model('products_model');
    $data['products_categories'] = $this->products_model->get_products_names('Aata');
    echo $data['products_categories']['name'];

And its giving me the following error, I don't know why
A Database Error Occurred

Error Number: 1054

Unknown column '$c_name' in 'where clause'

SELECT name FROM products WHERE category=$c_name

Filename: C:\wamp\www\OSW_appnsys\misystemsys\database\DB_driver.php

Line Number: 330

Any help will be highly appreciated !

A:

i may be deviating a little , but why dont you try something like this :
(Use active records makes the query more "readable")
Model:
public function get_products_names($c_name)
{
$this->db->select('name');
$this->db->where('category',$c_name);
$query = $this->db->get('products');
if($query->num_rows) 
return $query->result();
return false;
} 

controller :
$names_arr = array();
$this->load->model('products_model');
$result = $this->products_model->get_products_names('Aata');
foreach($result as $r){
array_push($names_arr,$r->name)
}
print_r($names_arr);

