Query sql codeigniter

Asked

Viewed 677 times

0

I have a table with dates and I would like to create a query that returns records with dates prior to the current day but I could not assemble this query; follows below 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: inserir a descrição da imagem aqui

2 answers

1

The consultation SQL normal in PHP would be as follows:

<?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

"
?>

1

I ended up solving it this way and it worked

$this->db->where('inicio <', date('Y-m-d'));
  • 1

    Mark your answer ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.