Verify that the column value is "Base"

0

I needed to check if the mytable table, in the mycolumn column, 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, this is not being able to resolve my code, ie it does not check, I think it has to do with this:

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

It does not seem to be the right syntax.

All kinds of help are welcome! PS: I just want to make it clear that I can get the value from the table, I just want to check if it has the value inside it.

    
asked by anonymous 25.06.2018 / 17:56

2 answers

0

Do this:

$name['mytable'][0]->mycolumn == 'meuvalor'
    
26.06.2018 / 16:39
0

In my model, I'm going to fetch all the data and columns from my table, I return this, after that, the controller stores the data in the $ name variable, and to refer to my column, just reference it after the variable put required) $ name ['mycolumn']. In other words, my syntax was correct, but the error was in the model, which sent me the values in string, so they are sent in type array and do not give any error, at least in the way I am using it!

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'){
                    //$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;
}
    
26.06.2018 / 16:57