0

I want order by query. My issue for the website is below.

I have a news table in my database and the table having order and date columns.

Now i want to display a news by today date with order of news.

For example : XXXx news having order 1 and yyyy news having order 1 and zzzz news having order 1 and aaa news order is 2.

I have displayed this value in ascending..so the result is

xxxx yyyy zzzz aaaa 

When i addded another news ie bbbb and order 1 then it's comes under zzzz

ie

xxxx yyyy zzzz bbbb aaaa 

But i want the result is

bbbb xxxx yyyy zzzz aaaa 

Note : The date is same date ie. today date

how do i get this? let me know

2
  • use order by date desc Commented Jul 30, 2013 at 7:27
  • If You do have only DATE column without time, then we can't help You Commented Jul 30, 2013 at 7:34

2 Answers 2

1

You have to use ORDER BY with multiply columns. That's what you have:

(value) (order) xxxx order=1 yyyy order=1 zzzz order=1 bbbb order=1 aaaa order=2 

And to get this:

(value) (order) bbbb order=1 xxxx order=1 yyyy order=1 zzzz order=1 aaaa order=2 

Just ORDER BY order and then by value.

ORDER BY order, value

Sign up to request clarification or add additional context in comments.

Comments

0
if your requirement is to show result from current date and order by order in ci then use this: $this->db->where("date",date('Y-m-s'));//whatever date format you have store in table place here $this->db->order_by("order","ASC"); //$this->db->order_by("order","DESC");// according to requirement Or if your requirement is to show result date wise on order wise both order and date then: $this->db->order_by("date","ASC"); $this->db->order_by("order","ASC"); $this->db->order_by("id","DESC"); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.