Welcome Guest, Not a member yet? Register   Sign In
issue CI_DB_oci8_result could not be converted to string
#1

[eluser]Sub-Zero[/eluser]
Hi!

I have created a controller that is doing this:
Example:
=================
function sample($valid){
$this->load->model('Db_sample_model', 'dbsample');
$othervalue = $this->dbsample->getothervalue($valid);
$results = $this->dbsample->getresults($othervalue, $valid);
==================
Here is an example of the sql statement for the model getothervalue >>
function getothervalue($valid){
$thevalue = $this->db->query("select value2 from table where value1 = '$valid'");
return $thevalue;
}
I did some printouts inside getothervalue, getresults and in the controller and was able to see the value of $valid. Dunno why I can't see or get the value of $othervalue - looks like I'm passing NULL. Any comments?

p.s. value1 and value2 are varchar...
#2

[eluser]kgill[/eluser]
Ok one quick comment for future reference, wrap your code in the [code] [/code] tags, it makes it a LOT easier for us to read.

Is that the actual SQL? naming your table "table" is just bad practice but anyway, can you post the table description, I want to see what column types value1 & value2 are. Also another thing to try, turn on profiling and take the generated query from the bottom of the page and dump it directly into sqlplus and try and run it. Do you get an error?
#3

[eluser]Sub-Zero[/eluser]
>>>Ok one quick comment for future reference, wrap your code in the tags, it makes it a LOT easier for us to read. ANSWER: OK Wink

>>>Is that the actual SQL? naming your table “table” is just bad practice but anyway, can you post the table description, ANSWER: No, "table" is not the name of the table. Like I said before, I'm just using an example.

>>>I want to see what column types value1 & value2 are. ANSWER: They are strings (ORACLE setup as VARCHAR).

>>>Also another thing to try, turn on profiling and take the generated query from the bottom of the page and dump it directly into sqlplus and try and run it. Do you get an error? ANSWER: I already did that and got no errors Wink
#4

[eluser]alboyd[/eluser]
How are you trying to check the value of $othervalue?

My guess is you are doing something like
Code:
echo $othervalue;

However you need to determine how many rows you are expecting to see returned from your query and understand that $othervalue is an object of query results. The results will be in the format of $othervalue->row(x)->value2 (based on your example query).

If you expect to only get one row returned then you would do something like to this to debug the value:
Code:
if ($othervalue->num_rows() == 1)
{
echo $othervalue->row(1)->value2;
}
#5

[eluser]Sub-Zero[/eluser]
alboyd, thanks! :coolsmile:




Theme © iAndrew 2016 - Forum software by © MyBB