NaN
NaN

Reputation: 1072

Multiple table queries using Codeingiter active record does not give intended result

I am storing number of rows returned from querying multiple tables, in a single Model function using Codeigniter Active Record Class, my model function looks like -

Model -

function my_model_function($param1)
{
     $step_passed = array();

        $step_passed['step1'] = 'pass'; 

       $query_table1 = $this->db->where('param1', $param1)
                                         ->get('table1');   

       if($query_table1->num_rows() > 0)
       {
        $step_passed['step2'] = 'pass';
       }

       $query_table2 = $this->db->where('param1', $param1)
                                    ->get('table2'); 
      if($query_table2->num_rows()> 0)
      {
          $step_passed['step3'] == 'pass';
      }

      return $step_passed;
} 

In my view as when I print_r this result -

Array([step1] => pass [step2] => pass)

However my expected result should be like -

Array([step1] => pass [step2] => pass [step3] => pass)

I confirm that the all tables[table1, table2, table3] have data matching param1 but I dont see table 3 result.

What I've tried -

 1.I tried printing the number of rows returned from query_table2 and
    it comes as 1 which is greater than 0, and I have no idea why my if    statement is not lighting up at this point
  2. I tried entering test key value pair inside my mode function like -

$step_passed['test_data'] = 'test';

and I see the result as -

Array([step1] => pass [step2] => pass [test] => test)

I having difficulty getting inside my if($query_table2->num_rows()> 0) statement which really returns 1, Can you please help me resolve it ?

Upvotes: 0

Views: 41

Answers (1)

user4094161
user4094161

Reputation:

@Siva

You have written

$step_passed['step3'] == 'pass';

And here you have used == operator, so please replace it with '='. So it should be like below

$step_passed['step3'] = 'pass';

Upvotes: 2

Related Questions