Select only one column from multiple rows in codeigniter. How to and is this more efficient?

Viewed 45196

I'm thinking about efficiency, and I'm not really sure about it one way or another.

But I have a bunch of rows with multiple columns. I just need the name field from all the rows where a certain other key is a certain value. I can get all these rows like this:

$this->db->where('res_id', $res_id);
$q = $this->db->get('products');
return $q->result();

then i can foreach through the array that it returns and only use name method of each object liek this:

foreach($returned_value as $fun):
    echo $fun->name;
endforeach;

But I'm wondering, would it be more efficient to only select the name attribute from each row, and I feel stupid asking it cause I've been using active record forever, but how would I go about this. I realize I could write it out using the $this->db->query() function, but is there a way to specify it using the main active record commands? Thanks.

1 Answers
Related