Query sql codeigniter

0

I have a table with dates and I would like to create a query that returns records with dates before the current day but I could not mount this query; below is my code and BD image:

function get_late_events($sort = 'idevento', $order = 'asc', $limit =null, $offset = null) {
    $this->db->order_by($sort, $order);

    if($limit){
        $this->db->limit($limit,$offset);
    }

    $this->db->select('idevento, cnome, inicio, fim, descricaoEvento, user, importancia');
    $this->db->from('eventos');
    $this->db->join('clientes','clientes.ccod = eventos.nomeEvento');
    $this->db->where('inicio', '<?php echo date('Y-m-d'); ?>');
    $query = $this->db->get(); 
    return $query->result();
}

Database:

    
asked by anonymous 01.07.2017 / 17:14

2 answers

1
The SQL normal query in PHP would look like this:

<?php 
$data = date('Y-m-d'); 

$sqlq = "

SELECT idevento, cnome, inicio, fim, descricaoEvento, user, importancia
FROM eventos xxx
LEFT JOIN clientes zzz ON (zzz.ccod = xxx.nomeEvento)
WHERE xxx.inicio = '$data'
ORDER BY xxx.inicio ASC

"
?>
    
01.07.2017 / 17:28
1

I solved it as follows and it worked.

$this->db->where('inicio <', date('Y-m-d'));
    
01.07.2017 / 18:10