CodeIgniter Forums

Full Version: [Solved] mySQL LEFT() function is not working fine with codeigniter...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]AlokRawat[/eluser]
Hi,

I am facing issue to get simple result using mySQL left function. Can anyone please help me..
My Model is given below:

Code:
function getAllList() {
        $fields = "id, title, category, LEFT(description, 200) desc";
        $this->db->select($fields);
        $r = $this->db->get("lists");
        if ($r->num_rows() > 0) {
            return $r->result();
        } else {
            return false;
        }
    }

using this code I am trying to get First 200 characters from description field. But I am getting given below error.

Quote:A Database Error Occurred

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 'desc FROM (`lists`) LIMIT 8' at line 1

SELECT `id`, `title`, `category`, LEFT(description, `200)` desc FROM (`lists`) LIMIT 8

Filename: C:\xampp\htdocs\ibtl\system\database\DB_driver.php

Line Number: 291

I don't why an extra ' coming before and after 200 near LEFT function.