Welcome Guest, Not a member yet? Register   Sign In
Profiler shows two queries when only one was executed?
#1

[eluser]alex646[/eluser]
Hey guys,


Please help me with the following:

CI profiler shows two queries when only one being executed

The query code:

Code:
public function search_user_profile($first_name, $last_name, $work, $school, $place_grewup, $place_last_met, $country_of_birth) {
        
        $this->db->select('work, school, place_grewup, place_last_met, country_of_birth');
        $this->db->select('first_name, last_name');
        $this->db->from('search_query');
        $this->db->from('user');
        $this->db->where('user.id = search_query.user_id');

         if ($first_name!=''){
          $this->db->like('first_name', $first_name); }
          if ($last_name!=''){
          $this->db->like('last_name', $last_name); }
        if ($work!=''){
          $this->db->like('work', $work);}
          if ($school!=''){
          $this->db->like('school', $school); }
           if ($place_grewup!=''){
           $this->db->like('place_grewup', $place_grewup); }
            if ($place_last_met!=''){
            $this->db->like('place_last_met', $place_last_met); }
             if ($country_of_birth!=''){
             $this->db->like('country_of_birth', $country_of_birth); }

        $query = $this->db->get();

           if($query->num_rows() >0) {
          
               foreach($query->result() as $row)
               {
          
                  $data[]=$row;      //assign each row from database to $data[] array
               }
                  
               return $data;  //this function returns $data[] array which has all the $rows from

           }
  }



  

}

Any input is appreciated!
#2

[eluser]rana[/eluser]
Can you please share the profiler output as well?
#3

[eluser]TheFuzzy0ne[/eluser]
If that's the case, you must be running the same query twice. If you do a file search for <your_model>->search_user_profile, you'll be able to spot where it's being called, and check your application flow. I suspect you're calling it twice without realising it. If you're still stuck, please post your controller code.
#4

[eluser]alex646[/eluser]
Thanks guys!

I've tracked the issue down:

You are right, I was running two queries at the same time by calling the same function twice : )





Theme © iAndrew 2016 - Forum software by © MyBB