Welcome Guest, Not a member yet? Register   Sign In
Problem with Where clause
#1

[eluser]Byrro[/eluser]
Hello,

My Model has this two methods:

Code:
/*
        What it does: search in the first DB an id ($id_table) that will be used
        in the second method to complete the name of the table
        */
        function consulta_id_table($codigo_cliente, $hashed_pim) {
            
            $database_name = 'vsk10c_'.$codigo_cliente;
            $table_name = 'vsk_'.$codigo_cliente.'_empresas';
            $column_name = 'id_table, hashed_pim';
            
            $DBempresa = $this->load->database("...", TRUE);
            $DBempresa->select($column_name);
            // $DBempresa->where('hashed_pim', $hashed_pim);
            $query = $DBempresa->get($table_name);
            
            return $query->result();
        
        }
        
        
        /*
        What it does: receive from the controller the $id_table and search
        for data in the specific table
        */
        function dados_para_menu_gerenciador($codigo_cliente, $id_table) {
            
            $database_name = 'vsk10c_'.$codigo_cliente;
            $table_name = 'vsk_'.$codigo_cliente.'_'.$id_table;
            
            $DBempresa = $this->load->database("...", TRUE);
            $DBempresa->select('nome_titulo, nome_sistema');
            $query = $DBempresa->get($table_name);
            
            return $query->result();
        
        }

And my Controller:

Code:
function header($hashed_pim = NULL) {
            
            $codigo_cliente = $this->_codigo_cliente();
            
            // call the first model´s method
            $this->load->model('Empresa');
            $returned_id_table = $this->Empresa->consulta_id_table($codigo_cliente, $hashed_pim);
            $id_table = $returned_id_table[0]->id_table;
            
            // pass the $id_table and get more data on the second model´s method
            $returned_dados_empresa = $this->Empresa->dados_para_menu_gerenciador($codigo_cliente, $id_table);
            
            // send this new data to the view
            $data['teste'] = $returned_dados_empresa;
            
            $this->load->view('view_header', $data);
        
        }

The problem is: look at the first method in the model class; there´s a line that is commented out with the following code:

Code:
// $DBempresa->where('hashed_pim', $hashed_pim);

When it´s commented out, the code works fine. But when I use the Where clause it just doesn´t work!.. It keeps giving this:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: controller

Line Number: " $id_table = $returned_id_table[0]->id_table; "
-------------------------------------
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controller

Line Number: " $id_table = $returned_id_table[0]->id_table; "
-------------------------------------
Fatal error: Call to a member function result() on a non-object in " return $query->result(); " on the second method

If I put the exact string that is passed from the variable $hashed_pim, like this:

Code:
$DBempresa->where('hashed_pim', 'hash_string_here');

Works. But not with the variable. I´ve tested it and the variable is passing the right string. What am I doing wrong? Would you have any tips?
#2

[eluser]danmontgomery[/eluser]
The first thing you did wrong was abandon an identical thread you made this afternoon: http://ellislab.com/forums/viewthread/165533/
#3

[eluser]WanWizard[/eluser]
Where is your call to controller->header()? I'd like to see what parameter you pass to it. Or is this a URI parameter?

Imho there is no way that "$DBempresa->where('hashed_pim', $hashed_pim);" gets translated by AR to "WHERE hashed_pim = '$hashed_pim'".




Theme © iAndrew 2016 - Forum software by © MyBB