Tried to make sort ordering db using codeigniter


This Content is from Stack Overflow. Question asked by enforeach zero

I Tried of making sort of names using Codeigniter but I found a problem, Please help me

Here is my data

  1. Doe Blablabla
  2. blablalba doe blablabla
  3. blablabla doe
  4. doe

I wanna sort it becomes like below but with some limit

  1. doe
  2. doe blablabla
  3. blablabla doe blablala
  4. blablabla doe

And here’s my code, but the sort won’t work yet

public function getFilter($name)
$this->db->select("*, (CASE people
    WHEN people = '$name' THEN 1
    WHEN people LIKE '$name%' THEN 2
        ELSE 3
    END) as people_name");
    $this->db->like('people', $id);
    $this->db->order_by("people_name asc");
    return $this->db->get()->result();


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?