Check that the column value is "Base"

Asked

Viewed 26 times

0

I needed to check if in the table mytable, in the column mycolumn, the value is 'meuvalor'.

My controller:

public function GetValue()
    {
            $this->config->set_item('language', $this->session->errorMessagesLang);
            $this->load->library('parser');
            $name= $this->admin_model->getmycolumn();
            if($name['mycolumn'] == 'meuvalor'){
                //fazer o que eu quero
            }
            echo $result;}

My model:

public function getmycolumn()
    {
        $this->db->select('mycolumn');
        $this->db->from('mytable');
        $result = $this->db->get()->result();
        return $result;
    }

My problem is ifstatement, it is not able to solve my code, that is not check, I think it has to do with this:

$name['mycolumn'] == 'meuvalor'

doesn’t seem like the right syntax.

Any kind of help is welcome! PS: I just want to make it clear that I can get the value from the table, I just want to check if you have inside it the value I want.

2 answers

0

Do it like this:

$name['mytable'][0]->mycolumn == 'meuvalor'
  • 1

    Already solved, I will put here the answer for future people who have this problem, or similar. But thank you anyway!

0

In my model, I will fetch all the data and columns of my table, return this, after that, the controller stores the data in the variable $name, and to reference my column just reference it after the variable putting (as necessary) $name['mycolumn']. In other words, my syntax was correct, but the error was in the model, which sent me the values in string, this way are sent in the type array and does not give any error, at least in the way I am using!

My handler:

public function GetValue()
    {
            $this->config->set_item('language', $this->session->errorMessagesLang);
            $this->load->library('parser');
            $name = $this->admin_model->getmycolumn();
            if($name['mycolumn'] == 'meuvalor'){
                    //$result = Fazer oq que eu quero
                    //echo $result;
            }
            elseif($name['mycolumn'] == 'meuvalor2'){
                //$result = Fazer oq que eu quero
                //echo $result;
            }     
    }

My model:

 public function getmycolumn() {
    $query = $this->db->query("SELECT * FROM mytable;");
    $row = $query->row_array();
    return $row;
}

Browser other questions tagged

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