I get an error to check the sql syntax near calc. Please explain as to where and why the issue is.
p.s: I just wanted to use calc in order by clause like this:

$this->db->order_by('calc','desc');
$this->db->get();

UPDATE: This is what i get while executing this query:

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as calc) FROM (products) JOIN categories ON categories.id=products.`ca' at line 1

Should it not be products.rating_1+products.rating_2+products.rating_3+products.rating_4+product‌​s.rating_5)/rated_by as calc . Try to print_r() the query ,and it should give you the formed SQL statement, easy for debugging.
–
JeemusuNov 28 '12 at 4:22

2 Answers
2

If you're going to use aliases then you'll not want to have CodeIgnioter automatically add ticks around your column names as it will blow things up. Just set the second paramter of select() to false to turn off this behaviour:

nopes not working...getting this error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as calc) FROM (products) JOIN categories ON categories.id=products.`ca' at line 1"
–
beNerdNov 28 '12 at 2:56