title: Concatenate data from multiple tables in codeigniter
body: <p>How do you guys get the data from two or more tables and manipulate it in codeigniter?</p>
  
  <p>Let's assume that we have 2 tables questions and answers. A question can have one or more answer. Now let's assume that an answer can have likes and unlikes. How do you people get all the questions with answers for display them in a view?. I will show you my solution but I'm curious about yours.</p>
  
  <p>I make use of libraries like so:</p>
  
  <pre><code>class Questions_library {
      var $CI = &amp;get_instance();
  
      function get_questions_with_answers(){    
          $data = array();
          $questions = $this-&gt;CI-&gt;questions_model-&gt;get_questions(); 
  
          if ($questions):
              foreach ($questions as $q): 
                  $temp = array();
                  $temp = $q;
                  $temp['answers'] = $this-&gt;CI-&gt;answerslibrary-&gt;get_answers($q['id']);
                  $data[] = $temp;         
              endforeach;    
          endif; 
  
          return $data ? $data : false;
      }
  }
  </code></pre>
  
  <p>Now in the answerslibrary i can take the same aproach to get the answers and answerlikes and unlikes.</p>
  
  <p>A draw back in my aproach is that if I want to display my questions with pagination sorted by number of answers or likes/unlikes etc i have to use join or nested queries inside my model and i canot make use of the power of my libraries.</p>
  
  <p>How do you manage this task ?</p>