title: CodeIgniter passing multiple arrays from controller to view
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index">PHP: “Notice: Undefined variable”  and “Notice: Undefined index”</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to pass both session data and a db query to a view in Codeigniter. I get an error in my view file that says: 'Message: Undefined variable: data'</p>
  
  <p>The problem lies with in the $idea variable. The variables register an undefined error. </p>
  
  <p>Controller: </p>
  
  <pre><code>public function members() {
  
      if($this-&gt;session-&gt;userdata('is_logged_in')){
          $session = $this-&gt;session-&gt;all_userdata();
          $facebook_id = $data['id']; 
  
  
          $this-&gt;load-&gt;model('idea'); 
          $idea = $this-&gt;idea-&gt;get_idea($facebook_id); 
  
          //merge the two arrays to get data variable
          $data = $session + $idea; 
          $this-&gt;load-&gt;view('members', $data); 
      } else {
          redirect('main/login'); 
      }
  }
  </code></pre>
  
  <p>Model: </p>
  
  <pre><code>public function get_idea($facebook_id) {
      $data = array(
          'id' =&gt; '', 
          'idea' =&gt; '', 
          'facebook_id' =&gt; $facebook_id
      );
  
      $query = $this-&gt;db-&gt;get('idea', $facebook_id); 
  
      return $query-&gt;result_array(); 
  
  }
  </code></pre>
  
  <p>Here are some of the resources I've used: <br />
  -<a href="https://stackoverflow.com/questions/3041616/creating-foreach-loops-using-code-igniter-controller-and-view">Creating foreach loops using Code Igniter controller and view</a> <br />
  -<a href="https://stackoverflow.com/questions/8756207/codeigniter-pass-array-from-controller-to-view">codeigniter: pass array from controller to view</a> <br />
  -<a href="http://blog.mattheufarmer.com/2010/building-a-website-in-codeigniter-part-ii-getting-data-and-using-it/" rel="nofollow noreferrer">http://blog.mattheufarmer.com/2010/building-a-website-in-codeigniter-part-ii-getting-data-and-using-it/</a> <br /></p>
  
  <p>Thank you for the help!</p>