[eluser]Unknown[/eluser]
Hi All,
I have a function that looks like this:
Code:
function get_document_list($curproj=0)
{
$this->db->select('document.*,users.firstname,users.lastname');
$this->db->from('document');
$this->db->join('users', 'users.id = document.document_director','left');
if($curproj > 0)
{
$this->db->where('document_project', $curproj);
}
$this->db->order_by('SUBSTR(`document_number`, 1,1) ASC, CAST(SUBSTR(`document_number`, 2) AS SIGNED) ASC');
$query = $this->db->get();
return $query->result();
}
The problem is that the query ends up like this:
Code:
SELECT `document`.*, `users`.`firstname`, `users`.`lastname` FROM (`document`) LEFT JOIN `users` ON `users`.`id` = `document`.`document_director` WHERE `document_project` = '23' ORDER BY SUBSTR(`document_number`, `1`, `1)` ASC, CAST(SUBSTR(`document_number`, `2)` AS SIGNED) ASC
Basically, it's putting backticks around the parameters for the SUBSTR MySQL function call. What would be the best way to handle this - do I need to just build my query and put it into a db->select() call with FALSE as the second parameter or is there another way?
Gary