[eluser]porangi[/eluser]
Hi,
To any admins watching - I posted this last night but it didn't seem to save/publish?
I'm trying to use some built in MYSQL string operations inside the $this->db->orderby() function and it fails. Is this possible? What am I doing wrong?
Code:
function findBy($criteria)
{
$this->db->where($criteria);
$this->db->order_by("LEFT(cLabel, '1') desc");
$this->db->order_by("RIGHT(cLabel, '1') asc");
$query = $this->db->get($this->table);
return $query;
}
cLabel is a string that look slike P1, M4, D1 etc.. so I'm trying to order them by letter and then number.
I have another function which works fine -
Code:
{
$sql = "SELECT `course`.`title` as course_title, `unit`.`uName` as unit_title, `criteria`.* FROM (`criteria`)
LEFT JOIN `units` as unit ON `unit`.`id` = `criteria`.`unit`
LEFT JOIN `courses` as course ON `course`.`id` = `unit`.`course`";
if($this->session->userdata("criteriafilter")!=0) { $sql .= " WHERE `criteria`.`unit` = ".$this->session->userdata("criteriafilter")." "; }
$sql .= "ORDER BY `course_title` desc, `unit_title` desc, LEFT(cLabel, 1) desc, RIGHT(cLabel, 1) asc
LIMIT ".$offset.", ".$count;
$query = $this->db->query($sql);
return $query;
}
and I could do it this way but I don't want to break form and stop using the
Code:
$this->db->where($criteria);
call which takes an associated array as this has wider consquences.
Any help would be appreciated
Chris
PS: still lovin CI and about to get company decals done for the van. Thinking CI logo may have to be there somewhere.