title: Undefined CodeIgniter variable
body: <p>Please, I don't know what am not getting right here... </p>
  
  <p>This is my controller:</p>
  
  <pre><code>$result = $this-&gt;Career_model-&gt;quick_search($gender, $country); // get the data once and then check if data empty or not
  if(!empty($result)){ // success
      $data['result'] = $result;
  }else{  // fail
      $data = $this-&gt;session-&gt;set_flashdata('error','No data found');
  }
  redirect('pages/search_result',$data);
  </code></pre>
  
  <p>And here is the view:</p>
  
  <pre><code>if((isset($result)) &amp;&amp; (!empty($result))): // checking if the result is empty
      foreach ($result as $key =&gt; $value):
              echo $value-&gt;name;
      endforeach;
  else:
      echo "No result was found."; // this is the part that gets executed
  endif;
  </code></pre>
  
  <p>But once I change my controller to this:</p>
  
  <pre><code>$result = $this-&gt;Career_model-&gt;quick_search($gender, $country); // get the data once and then check if data empty or not
  
  if(!empty($result)){ // success
     $data = $this-&gt;session-&gt;set_flashdata('error','No data found'); //this is the part that gets executed, meaning that my result is not empty. 
  }else{  // fail
     $data['result'] = $result;
  }
  redirect('pages/search_result',$data);
  </code></pre>
  
  <p>And the view to this:</p>
  
  <pre><code>foreach ($result as $key =&gt; $value):
          echo $value-&gt;name;
  endforeach;
  </code></pre>
  
  <p>I only end up with an <code>Undefined variable: result</code> error message. What am I doing wrong?</p>