title: Sometime response not getting from database in codeigniter
body: <p>I created level based login for agents where they click on start button and those records which is not assigned to anyone will assign the agent who clicked the start button.</p>
  
  <p>It's Working fine but sometimes when agent clicked on start button then query didn't give any response from table then and the code which is already assign to agent also not display in panel( also not getting already assigned code to agent because not getting response from table).</p>
  
  <p>This all happening from ajax call</p>
  
  <p>When agent logout and again login then code start showing on his panel.</p>
  
  <p>This issue i am facing in codeigniter and mysql, Please help me where is the exact issue.</p>
  
  <p>Here is the sample code</p>
  
  <p>1) I called the function</p>
  
  <pre><code>   public function emp_start_time(){
      // x($_SESSION);
      ini_set('memory_limit', '2048M'); // 2gb
      ini_set('max_execution_time', 3600); //60 min
  
      $role_id    = $this-&gt;session-&gt;userdata('role_id');
      $login_id   = $this-&gt;session-&gt;userdata('login_id');
      $type       = $_POST['type'];
      $table_data = $this-&gt;user_data_for_emp($type);
      // x($table_data);
      if(!empty($table_data)){
          $data['table_data'] = $table_data;
          $table = $this-&gt;load-&gt;view('aof/panel/individual_def_filter_table',$data,true);
          $response_data = ['status' =&gt; 'success','msg' =&gt; 'data fetched succesfully','data' =&gt; $table]; 
      }else{
          $response_data = ['status' =&gt; 'error','msg' =&gt; 'No data found','data' =&gt; ''];
      }
      echo json_encode($response_data);
  }
  </code></pre>
  
  <p>2) From emp_start_function we called another function and get query and display in table</p>
  
  <pre><code>public function user_data_for_emp($type,$user_id = '',$post_data = ''){
      $role_id        = $this-&gt;session-&gt;userdata('role_id');
      $login_id       = $this-&gt;session-&gt;userdata('login_id');
      $task_of_role   = $this-&gt;session-&gt;userdata('task_of_role');
      $where_data     = '';
      // y($type);x($post_data);
      if($type == 'assign'){
          $esign_today_date = date('Y-m-d');
          $where_data .= '(video = 1 or uad.ipv = 1) and sign != 0 and mf_only = 0 and  date(ed.esign_date) &gt;= "2018-12-01" and date(ed.esign_date) &lt;= "'.$esign_today_date.'" and '; 
  
          if($task_of_role == '1,2' || $task_of_role == '2' || $task_of_role == '8'){
              $where_data .= "login_id = 0 and client_id != '' and ucc_done = 0 and client_interested = 0";
              $order_by = "esign_date ASC";
          }else{
              $where_data .= "login_id = 0 and client_id = '' and ucc_done = 0 and client_interested = 0";
              $order_by = "esign_date ASC";
          }
  
      }else if($type == 'load'){
          // $where_data .= 'login_id ="'.$login_id.'" and client_interested = 0';
          $where_data .= 'login_id ="'.$login_id.'" and ucc_done = 0 and client_interested = 0 and uad.mf_only = 0';
          $order_by = "esign_date ASC";
      }else if($type == 'task_comp'){
          $where_data .= 'ua.id ="'.$user_id.'"';
          $order_by = "esign_date ASC";
      }else if($type == 'def_filter'){
          // $where_data .= 'login_id ="'.$login_id.'" and date(uad.def_mail_sent_date) &gt;= "'.$post_data['from_date'].'" and date(uad.def_mail_sent_date) &lt;= "'.$post_data['to_date'].'"';
          $where_data .= 'login_id ="'.$login_id.'" and date(uad.def_mail_sent_date) &gt;= "'.$post_data['from_date'].'" and date(uad.def_mail_sent_date) &lt;= "'.$post_data['to_date'].'" and uad.mf_only = 0';
  
          if(!empty($post_data['states'])){
              if($post_data['states'] == 1){ //south
                   $where_data .= ' AND ua.p_state IN ("'.implode('","', SOUTH_LEAD_STATES).'")';
              }else{ //Non south
                  $where_data .= ' AND ua.p_state NOT IN ("'.implode('","', SOUTH_LEAD_STATES).'")';
              }
          }
  
          $order_by = "uad.def_mail_sent_date DESC";
  
      }
  
      if($type == 'assign'){
          $select_data = 'ua.id, ua.client_id, ua.ekyc, ua.acc_ownership, ua.form_received, ed.id as def_id, ed.pan as doc_pan, ed.cancelled_cheque, ed.signature, ed.income_proof, ed.photograph, ed.address_proof, ed.poa, ed.video_segments, ed.e_sign_pan, ed.poa_document_received, uad.sign_time, ed.esign_date, uad.sign,             uad.techexcel_export, uad.kyc_mode, uad.ucc_done, uad.login_id, uad.role_status, uad.ipv, uad.def_mail_sent_date, uad.uploaded_date,
          ';
      }else{
         $select_data = 'ua.id, ua.client_id, ua.ekyc, ua.name, ua.email, ua.acc_ownership, ua.mobile, ua.ms_name, ua.pan, ua.segment, ua.p_state, ua.kra_status, ua.kra_status_code, ua.kra_fetch_time, ua.date_created, ua.kra_email, ua.form_received, ua.bank_verfiy, ua.mf_registered, ed.id as def_id, ed.pan as doc_pan, ed.cancelled_cheque, ed.signature, ed.income_proof, ed.photograph, ed.address_proof, ed.poa, ed.video_segments, ed.e_sign_pan, ed.poa_document_received, ed.nach_document_received, uad.name_as_per_pan, uad.video_time, uad.sign_time, ed.esign_date, uad.sign, ua.kra_document_fetch,
          uad.techexcel_export, uad.kyc_mode, uad.ucc_done, uad.login_id, uad.role_status, uad.ipv, uad.def_mail_sent_date, uad.uploaded_date,
          '; 
      }
  
      $params                     = [];
      $params['env']              = 'sm_db';
      $params['table_name']       = 'sm_user_account ua';
      $params['select_data']      = $select_data;
      $params['where']            = TRUE;
      $params['where_data']       = $where_data;
      $params['where_escape']     = false;
      $params['join']             = TRUE;
      $params['multiple_joins']   = TRUE;
      $params['join_table']       = array('sm_ekyc_deficiency ed','sm_user_account_details uad');
      $params['join_on']          = array('ua.id = ed.user_id','ua.id = uad.user_id');
      $params['order_by']         = $order_by;
      $params['join_type']        = array('LEFT','LEFT');
      // $params['print_query_exit'] = true;
  
      $table_data = $this-&gt;comm-&gt;get_table_data_with_type($params);
      // x($table_data);
      $remark_list = $this-&gt;getStandardRemarkList();
      // x($remark_list);
  
      if($type != 'assign'){
          $i = 0;
          foreach($table_data as $k =&gt; $v){
              $params                 = array();
              $params['env']          = 'sm_db';
              $params['select_data']  = 'id';
              $params['table_name']   = 'sm_ekyc_uploads';
              $params['where']        = true;
              // $params['print_query_exit']        = true;
              $params['where_escape'] = false;
              $params['where_data']   = array('user_id' =&gt; $v-&gt;id,'type' =&gt; 'cancelled_cheque');
              $params['order_by']         ="id DESC";
              $params1['limit_data']       = "1";            
              $res = $this-&gt;comm-&gt;get_table_data_with_type($params)[0]-&gt;id;
              $table_data[$i]-&gt;c_cheque = $res;
  
              $params                 = array();
              $params['env']          = 'star_db';
              $params['select_data']  = 'login_name';
              $params['table_name']   = 'sm_login_master';
              $params['where']        = true;
              // $params['print_query_exit']        = true;
              $params['where_escape'] = false;
              $params['where_data']   = array('login_id' =&gt; $v-&gt;login_id);
              $login_data = $this-&gt;comm-&gt;get_table_data_with_type($params)[0]-&gt;login_name;
              if(!empty($login_data)){
                  $table_data[$i]-&gt;login_name = $login_data;
              }else{
                  $table_data[$i]-&gt;login_name = ''; 
              }
  
              $params                     = [];
              $params['env']              = 'sm_db';
              $params['table_name']       = 'sm_user_mgt_history umg';
              $params['select_data']      = 'umg.login_id,lm.login_name,rc.name_of_role';
              $params['where']            = TRUE;
              $params['where_data']       = array('umg.user_id' =&gt; $v-&gt;id);
              $params['join']             = TRUE;
              $params['multiple_joins']   =TRUE;
              // $params['join_table']       = STAR_DB.'.sm_login_master lm';
              $params['join_table']       = array(STAR_DB.'.sm_login_master lm',STAR_DB.'.sm_role_creation rc');
              $params['join_on']          = array('umg.login_id = lm.login_id','umg.role_id = rc.role_id');
              // $params['join_on']          = 'umg.login_id = lm.login_id';
              $params['order_by']         = "umg.id ASC";
              // $params['join_type']        = 'LEFT';
              $params['join_type']        = array('LEFT','LEFT');
              $params['return_array']     = true;
              // $params['print_query_exit'] = true;
  
              $login_his_data = $this-&gt;comm-&gt;get_table_data_with_type($params);
              // x($login_his_data);
  
              if(!empty($login_his_data)){
                  $user_data = $login_his_data;
              }else{
                  $user_data = [];
              }
  
              $table_data[$i]-&gt;user_data = $user_data;
  
              // Remarks of users
              $params                 = array();
              $params['env']          = 'sm_db';
              $params['select_data']  = 'id,remark,standard_remark_flg,executive_id';
              $params['table_name']   = 'sm_remarks';
              $params['where']        = true;
              // $params['print_query']  = true;
              $params['where_data']   = array('user_id' =&gt; $v-&gt;id);
              $params['order_by']     ="id DESC";
              $remarks = $this-&gt;comm-&gt;get_table_data_with_type($params)[0];
              if($remarks-&gt;standard_remark_flg != 5){
                  $table_data[$i]-&gt;latest_remarks = $remark_list[$remarks-&gt;standard_remark_flg]['remark'];
              }
              else{
                  $table_data[$i]-&gt;latest_remarks = $remarks-&gt;remark;
              }
  
              $umg_param                     = [];
              $umg_param['env']              = 'sm_db';
              $umg_param['table_name']       = 'sm_user_mgt_history umg';
              $umg_param['select_data']      = 'umg.id as umg_id';
              $umg_param['where']            = TRUE;
              $umg_param['where_data']       = array('umg.user_id' =&gt; $v-&gt;id,'umg.login_id' =&gt; $login_id,'status'=&gt;0);
              $table_data[$i]-&gt;umg_id = $this-&gt;comm-&gt;get_table_data_with_type($umg_param)[0]-&gt;umg_id;
  
              $table_data[$i]-&gt;executive = $remarks-&gt;executive_id;
  
              $i++;
          }
      }
  
      // x($table_data);
      return $table_data; 
  }
  </code></pre>
  
  <p>3) But sometimes i getting no data found msg which is written in else part</p>
  
  <p>Thank you in advance</p>