views:

30

answers:

1

I'm using MySQL ActiveRecord with CodeIgniter to submit queries, but have run into some snags when using the "select" function. For instance, this MySQL query works perfectly within phpMyAdmin:

SELECT review_id, firms_name
FROM reviews AS r
JOIN firms AS f ON f.firms_id = r.review_target_id
WHERE r.review_id =3
ORDER BY r.review_timestamp DESC
LIMIT 0 , 30

It gives me two columns, exactly what I need.

However, this only gives me one column, "review_id":

$this->db->select('review_id', 'firms_name');
$this->db->from('reviews as r');
$this->db->join('firms as f', 'f.firms_id = r.review_target_id');
$this->db->where('r.review_id', $id);
$this->db->order_by('r.review_timestamp', 'desc');
$query = $this->db->get();

If I delete the 'select' clause, I get all the information I need, but would like to understand what I'm doing wrong and how I can reduce the load on my db. Any thoughts?

+3  A: 
$this->db->select('review_id', 'firms_name');

should be written like this (the column names should be a single string):

$this->db->select('review_id, firms_name');

Also, remember that you can always use $this->db->last_query(); to output the last query that was run, so you can see the exact SQL statement being executed.

Colin
Thanks for the quick response. As always, if I were more careful, I wouldn't have these problems to begin with. Many thanks.
tchaymore
@tchaymore: Glad I could help!
Colin