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!