title: How to prepare a model to return json_encode result ( Codeigniter )
body: <p>Here is my Model in Codeigniter with foreach loop in it.</p>
  
  <p>Function.</p>
  
  <pre><code>  public function get_projectcount($qup) {
      echo'[';
      foreach ($qup as $row) {
          $id = $row['myid'];
          $this-&gt;db-&gt;select('*');
          $this-&gt;db-&gt;from('projects');
          $this-&gt;db-&gt;where(array('projects.accountId' =&gt; $id));
          $query = $this-&gt;db-&gt;get();
  
          $projects_count = count($query-&gt;result());
          echo '{"myid":"' . $row['myid'] . '",';
          echo '"total_projects":"' . $projects_count . '"},';
      }
      echo']';
  }
  </code></pre>
  
  <p>I want this as a result of json_encode.</p>