Problem with active records

#1
[eluser]Unknown[/eluser]
Hello! I've just started using CodeIgniter and found it surprisingly easy to use (I switched from ZF). Now I have ran into my first problem, which has to do with Active records (which I haven't used before)

I have a function that looks like this:
Code:
function get_top_rated_movies($limit_num_of_movies) {
            $this->db->select("title, TRUNCATE((rating_acting+rating_dvd+rating_overall)/3, 1) as avg_rating");
            $this->db->order_by("avg_rating", "DESC");
            $this->db->limit($limit_num_of_movies);
            $query = $this->db->get();

            return $query;
        }

This will return an error:
Quote: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 avg_rating FROM (`dvd_collection`) ORDER BY `avg_rating` DESC LIMIT 20' at line 1

SELECT `title`, TRUNCATE((rating_acting+rating_dvd+rating_overall)/3, `1)` as avg_rating FROM (`dvd_collection`) ORDER BY `avg_rating` DESC LIMIT 20

For some reason it encloses 1) with singular quotation-marks. Is there something I have missed here? It's seems very odd to me.

(Sorry if my language seems to be a bit off, I'm from Sweden)

#2
[eluser]WanWizard[/eluser]
Use the second parameter of $this->db->select() to prevent escaping. The select method escape functionality can't handle much more than just a list a fields...

#3
[eluser]Unknown[/eluser]
That worked. Thanks!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.