WHERE condition does not work

Asked

Viewed 112 times

0

I’m trying to put a condition in a function and it’s not working... I tried to put this condition but it didn’t work $this->db->where('idUser =', $this->session->userdata('id'));
Usually all condition do as the code below, but only this that did not work.

function get($table, $fields, $where = '', $perpage = 0, $start = 0, $one = false, $array = 'array')
{

    $this->db->select($fields.', clientes.nomeCliente, clientes.idClientes');
    $this->db->from($table);
    $this->db->limit($perpage, $start);
    $this->db->join('clientes', 'clientes.idClientes = '.$table.'.clientes_id');
    $this->db->order_by('idVendas', 'desc');
    $this->db->where('idUser =', $this->session->userdata('id'));

    if ($where) {
        $this->db->where($where);
    }

    $query = $this->db->get();

    $result =  !$one  ? $query->result() : $query->row();
    return $result;
}
  • Utilizes print_r($this->db->last_query()); for you to have the SQL of that query and check if it is correct and works directly in the bank.

  • Perhaps on account of join you need to specify which field table idUser, for example: $this->db->where('nomeDaTabela.idUser =', $this->session->userdata('id'));

3 answers

0

On that first line:

$this->db->select($fields.', clientes.nomeCliente, clientes.idClientes');

That "dot" and that "single quote" before the comma, they’re not wrong?

The point should not exist there, and the quote should be opened in clients..

And in the WHERE

$this->db->where('idUser =', $this->session->userdata('id'));

Try to remove the signal from "=".

-1

Only one question is the framework codeigniter that you’re wearing, if I think you’re in your condition:

$this->db->where('idUser', $this->session->userdata('id'));

In the codeigniter or use the( = ) or ( , ) when you want to use the function of equally between two values.

-1

$this->db->where('idUser',$this->session->userdata('id'));
  • In codeigniter you can insert a comparison operator along with the first parameter.

Browser other questions tagged

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