Return Date data according to the month

0

I have developed the following function:

public function get_agendas()
{
    $this->db->select("*, EXTRACT(MONTH FROM data) as mes_referencia, count(id) as total_registros");
    $this->db->where("data >=", date("Y-m-d"));
    $this->db->group_by("EXTRACT(MONTH FROM data)");
    $this->db->order_by('id', 'ASC');
    $consulta = $this->db->get('agenda')->result();

        foreach($consulta as $valor){
            $valor->lista_agenda = $this->db->get('agenda')->result();
        }

    return $consulta;
}

My question is this: At the time of listing all the records that belong to that month, how would I do SQL?

I have 4 records in the database:

I need to display as follows:

Month 04       Record 1       Record 2

Month 05       Record 1

Month 06       Record 1

The first part, I know that I will search how many records I can until I display the month correctly, but in the second part of the code inside foreach (), I do not know how to do it. Thanks!

    
asked by anonymous 04.04.2016 / 02:59

1 answer

0

Your question is not clear, so I will answer for what I have entedi.

When you want to know the amount of data for a specific Month

select count(1) from horarioverificacao where EXTRACT(MONTH FROM data)=3

Below if you want to know the total for months

select  EXTRACT(MONTH FROM data) ,count(1) from horarioverificacao 
group by EXTRACT(MONTH FROM data)
    
05.04.2016 / 15:46