为什么可能在7月之前到来

时间:2013-07-18 09:25:33

标签: php mysql codeigniter

我希望按月降序获得月份名称,但我可能会在7月到2月之前获得。这是为什么?我正在使用codeigniter。

$this->db->select("MONTHNAME(`published_date`) as month");
$this->db->group_by("MONTH(`published_date`)");
$this->db->where("status", "yes");
$this->db->where("YEAR(`published_date`)", $year);
$this->db->where("category_id", $id);
$this->db->order_by("MONTHNAME(`published_date`)", 'DESC');
$result = $this->db->get('tbl_news')->result();

在我的数据库中,我有feb,可能和7月保存为日期。但是我可能,7月和7月而不是7月,可能,非常。 欢迎任何帮助/建议。

2 个答案:

答案 0 :(得分:2)

而不是

$this->db->order_by("MONTHNAME(`published_date`)", 'DESC');

使用

$this->db->order_by("`published_date`", 'DESC');

答案 1 :(得分:1)

试试这个

$this->db->order_by("EXTRACT(MONTH FROM `published_date`)", 'DESC');

而不是

$this->db->order_by("MONTHNAME(`published_date`)", 'DESC');
相关问题