title: Mysql query and foreach query with double items
body: <p>I am just grabbing user data from a few tables but users have the option of adding more than one skill or exp. </p>
  
  <pre><code>$query_str = "SELECT a.*, b.*, c.*, d.*, e.* FROM edu a
                JOIN exp b ON a.user_id=b.user_id
                JOIN user_profiles c ON a.user_id=c.user_id
                JOIN skills d ON a.user_id=d.user_id
                JOIN comp e ON a.user_id=e.user_id
                WHERE a.user_id = ?";
  
  $query = $this-&gt;db-&gt;query($query_str, $end_user);
              if($query-&gt;num_rows() &gt; 0) {
                      foreach($query-&gt;result_array() as $stuff) {
                              $data[] = $stuff;
                      }
                      return $data;
                      } else {
              return false;
                      }
  </code></pre>
  
  <p>Everything is fine until I try to display the data. If a user has two exp, everything else is showing up twice. I m not sure how to write this. Would it be easier to do separate them? One query for each item? </p>
  
  <pre><code>public function get_education()
      {
             $one_edu = $this-&gt;test_model-&gt;one_edu($end_user);
              if ($one_edu != false)
              {
                      foreach($one_edu as $edas) {
                              $one_edu_html .='&lt;p&gt;'.$edas['objective'].'&lt;/p&gt;';
                      }
  
                      foreach($one_edu as $exp) {
                              $one_edu_html .= '&lt;p&gt;'.$exp['exp_title'].'&lt;/p&gt;';
  
                      }
  
                      foreach($one_edu as $educ) {
                              $one_edu_html .= '&lt;p&gt;'.$educ['edu_title'].'&lt;/p&gt;';
                      }
  
                      $result = array('status' =&gt; 'ok', 'content' =&gt; $one_edu_html);
                      echo json_encode($result);
                      exit();
              }else{
                      $result = array('status' =&gt; 'ok', 'content' =&gt; '');
                      echo json_encode($result);
                      exit();
              }
      }
  </code></pre>
  
  <p>Now it s returning something like this:</p>
  
  <pre><code>Objective
  Exp title1
  Exp title2
  Edu title
  Edu title &lt;- Extra
  </code></pre>
  
  <p>Using codeigniter</p>