How to perform two functions from the same table

Asked

Viewed 85 times

-2

I have this Function to group values of two tables "sales" and "customers", but in addition to grouping this information, I need to perform a search in the database according to the parameters. I can’t put the two together, I run only one at a time. How to do?

function getVendas()
{
$this->db->select('vendas.*, clientes.nomeCliente');
    $this->db->from('vendas');
    $this->db->join('clientes', 'clientes.idClientes = vendas.clientes_id');      
    $this->db->limit(10);
    return $this->db->get()->result();
}



 function getVendas()
{
    $sql = "SELECT * FROM vendas WHERE dataVenda BETWEEN CURRENT_DATE()-7 AND CURRENT_DATE() AND faturado = 0";
    return $this->db->query($sql)->result();
}
  • What is the name of the DB engine and what is the name of the DB access lib?

1 answer

0


In the first query you are using the query Builder you can simply add your query.

public function getVendas()
{
    $this->db->select('vendas.*, clientes.nomeCliente');
    $this->db->from('vendas');
    $this->db->join('clientes', 'clientes.idClientes = vendas.clientes_id');      
    $this->db->where('vendas.dataVenda BETWEEN CURRENT_DATE()-7 AND CURRENT_DATE()', null, false);
    $this->db->where('vendas.faturado', 0);
    $this->db->limit(10);
    return $this->db->get()->result();
}

This way you’re doing the research on your Join.

  • 1

    It worked! Thank you very much.

Browser other questions tagged

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