Codeigniter - Syntax error with select and Where

Asked

Viewed 38 times

0

In a precise project that appears only the active publications on the main page I am using Codeigniter, I used the following lines of code:

Model:

$this->db->select('*');
$this->db->from("publicacoes");
$this->db->where('ativacao' == '1');
$data = $this->db->get()->result_array();

return $data;

But when I leave this line "uncommented" the application "breaks"

$this->db->where('ativacao' == '1'); 
  • Only a hint, instead of using the from line, you can already put the table name inside the get thus: $this->db->get('publicacoes')->result_array();

2 answers

2


Alter $this->db->where('ativacao' == '1'); for $this->db->where("ativacao = '1'");

  • 1

    Thanks! It worked +1

1

According to the documentation on the Codeigniter website, the "ideal" way to do this would be:

$this->db->where('ativacao' , '1');

and when you’re going to use one where <> there you stay

$this->db->where('ativacao <>' , '1');
  • +1 Thank you very much for the information

Browser other questions tagged

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