Welcome Guest, Not a member yet? Register   Sign In
db query during another query
#1

[eluser]Unknown[/eluser]
Hi,

Let's say I have the following code:

Code:
function getSomeVal(){
//using $this->db->where and get to retrieve and return some value from some table
  
}

//main query
$this->db->where('id', $id);
$this->db->update('mytable', array ('someVal'=>getSomeVal());

As you can see, during while building the main query, I'm calling a function which (to return a value) also builds a query.

I suppose this will not work, what's the solution to this problem? I may forget that the getSomeVal() function also uses db object...
#2

[eluser]darrentaytay[/eluser]
Code:
function getSomeVal(){
//using $this->db->where and get to retrieve and return some value from some table
  
}

$value = getSomeVal();

$this->db->where('id', $id);
$this->db->update('mytable', array ('someVal' => $value);
#3

[eluser]Unknown[/eluser]
Thanks,

Yes, I know I can do that, but I have to remember about doing thatSmile

btw: but am I actually right that my version will not work? Because I actually can't test it right now.
#4

[eluser]darrentaytay[/eluser]
I think your version would work fine Smile




Theme © iAndrew 2016 - Forum software by © MyBB