Welcome Guest, Not a member yet? Register   Sign In
using a query result in another query binding?
#1

I've done a sql query and I get a structure called query2. I'd like to use the item (coding) to search a different table. 



Code:
$query2 = {CI_DB_mysqli_result} [8]
conn_id = {mysqli} [19]
result_id = {mysqli_result} [5]
result_array = {array} [0]
result_object = {array} [1]
  0 = {stdClass} [1]
   item = "coding"

But when I do the following I get an error "Object of class stdClass could not be converted to string". Can I cast it to a string? I'd like $item to be "coding". 
Code:
             $item=$query2->result();

             $sql3 = "SELECT a.qualified
                      FROM standard_activities sa, relation r, activity a WHERE sa.activity=? AND sa.id=a.id";
             $query3=$this->db->query($sql3, array($item));
How can I get the binding SQL to work?
proof that an old dog can learn new tricks
Reply
#2

Solved! I used this:
foreach ($query2->result_array() as $row2)
{
//check to see if item is qualified and if yes, then add to qualified, not_qualified, or notApp count
$item=$row2['item'];
$sql3 = "SELECT a.qualified
FROM standard_activities sa, relation r, activity a WHERE sa.activity=? AND sa.id=a.id";
$query3=$this->db->query($sql3, array($item));
}
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB