问题描述:

I want to get month names in descending order but I am getting may before july and then february. Why is this?I am using 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();

In my database I have feb, may and july saved as date. But I am getting may , july and feb instead of july, may, feb.

Any help/suggestions are welcome.

网友答案:

instead of

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

use

$this->db->order_by("`published_date`", 'DESC');
网友答案:

Try this

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

instead of

$this->db->order_by("MONTHNAME(`published_date`)", 'DESC');
相关阅读:
Top