Problem with data returned from query |
[eluser]Byrro[/eluser]
Hello, I have a model with the following function: Code: function consulta_id_table() { Then, in the Controller: Code: function header() { When I print_r the variable $test in the view file, I have the following result: Quote:Array ( [0] => stdClass Object ( [id_table] => 001 ) ) Just fine. But then I have problem with this: in the controller, I have do manipulate the variable $returned_id_table to use this result as an argument to call another Model method, instead of sending it to the view. I´m doing the following in the same controller method: Code: function header() { It returns this error: Quote:A PHP Error was encountered I´ve tried with '0': Code: $id_table = $returned_id_table['0']->id_table; Quote:A PHP Error was encountered What´s going on? Could someone please help me find where is the mistake?
[eluser]WanWizard[/eluser]
If I copy and paste that code in my controller here (and replace your method with a query that returns the same result ), $id_table contains the integer 1, and I don't get the notice error. Are you sure your query returns a correct result?
[eluser]Byrro[/eluser]
[quote author="noctrum" date="1282789300"] Code: print_r($returned_id_table); When the where clause is commented out, print_r($returned_id_table) shows: Quote:Array ( [0] => stdClass Object ( [id_table] => 001 [hashed_pim] => 05e3c00bdb22b2b7b6ed1d1358456ac1bdf28420 ) ) When I turn on the Where clause, it shows an empty array... The variable $hashed_pim is passed from the URI: website.com/controller/empresas/hash_string Inside the first model´s method, it receives the $hashed_pim but doesn't work with the Where clause. I think it´s a problem with the syntax when passing the arguments to Where...
[eluser]danmontgomery[/eluser]
Quote:Call to a member function result() on a non-object in ” return $query->result(); ” on the second method Means there's an error in your query. Code: echo $DBempresa->last_query();
[eluser]Byrro[/eluser]
[quote author="noctrum" date="1282790219"] Quote:Call to a member function result() on a non-object in ” return $query->result(); ” on the second method Means there's an error in your query. Code: echo $DBempresa->last_query(); That´s it! The last_query(): SELECT `id_table` FROM (`vsk_010121_empresas`) WHERE `hashed_pim` = '$hashed_pim' It´s not sending to the Where clause the string of the variable, but the $variable name... How can I fix that?
[eluser]WanWizard[/eluser]
You example given doesn't mention this query, do we need to guess to what you have exactly coded? You are passing a variable name as a string.
[eluser]danmontgomery[/eluser]
[quote author="WanWizard" date="1282822462"]You example given doesn't mention this query, do we need to guess to what you have exactly coded?[/quote] He created an identical thread that did have the relevant information in it: http://ellislab.com/forums/viewthread/165560/ |
Welcome Guest, Not a member yet? Register Sign In |