one_loop
one_loop

Reputation: 23

Codeigneter : How to use Order by in Active record?

I have a database column "days". I would like to insert the days of the week randomly example Tuesday,Monday,Thursday,Wednesday

| id | Days
-------------------
| 1  | Tuesday
| 2  | Monday
| 3  | Thursday
| 4  | Wednesday

How would I return the days in order to my view using Codeigniter Active Record ?

Upvotes: 2

Views: 50

Answers (1)

TIGER
TIGER

Reputation: 2907

If the column Days only contains the day of week, then you could do this:

$this->db->query(SELECT * FROM TABLENAME ORDER BY FIELD(Days, 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY'));

Upvotes: 1

Related Questions