0

クエリごとに並べたい。ウェブサイトの私の問題は以下の通りです。

データベースにニューステーブルがあり、テーブルには順序と日付の列があります。

今日の日付までのニュースをニュースの順序で表示したいと思います。

例: XXXx ニュースの順序は 1 で、yyyy ニュースの順序は 1 で、zzzz ニュースの順序は 1 で、aaa ニュースの順序は 2 です。

この値を昇順で表示したので、結果は

xxxx
yyyy
zzzz
aaaa

別のニュース、つまり bbbb と order 1 を追加すると、zzzz の下に表示されます

すなわち

xxxx
yyyy
zzzz
bbbb
aaaa

しかし、私は結果が欲しい

bbbb
xxxx
yyyy
zzzz
aaaa

注:日付は同じ日付です。今日の日付

どうすればこれを入手できますか? お知らせ下さい

4

2 に答える 2

1
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");
于 2013-07-30T07:44:38.653 に答える
1

ORDER BY乗算列で使用する必要があります。それはあなたが持っているものです:

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

そして、これを取得するには:

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

ちょうどORDER BY orderそれからvalue

ORDER BY order, value

于 2013-07-30T07:36:48.580 に答える