Php 为什么五月早于七月

Php 为什么五月早于七月,php,mysql,codeigniter,Php,Mysql,Codeigniter,我想按降序得到月份名称,但我要在7月之前得到5月,然后是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(`publi

我想按降序得到月份名称,但我要在7月之前得到5月,然后是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();
在我的数据库中,2月、5月和7月被保存为日期。但是我得到的是五月、七月和二月,而不是七月、五月、二月。 欢迎提供任何帮助/建议。

而不是

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

试试这个

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

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

因为,它使用的是ascii值monthshow的实际输出