title: How do I combine two MySQL rows into one and display them in a table using PHP?
body: <p>I have a table "exercise_results". People put in their results at the beginning and then two months later put in their results to see how much they improved. Their beginning set has the exercise_type_id of "1" and the end set has the exercise_type_id of "2".</p>
  
  <p>I need a way to display this out into a HTML table that looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/2s4h5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2s4h5.png" alt="Normally I do this using"></a> </p>
  
  <p>a foreach loop, but that's with single rows. I'm having trouble combining two rows into one. I think this may be as simple as some kind of MySQL join? We identify each person by their person_unique_id.</p>
  
  <p>Here are my fields:</p>
  
  <pre><code>id | person_unique_id | person_name | exercise_type_id | mile_running_time | bench_press_weight_lbs | squat_weight_lbs | date_of_exercise_performed
  </code></pre>
  
  <p>Sample rows:</p>
  
  <pre><code>1 | J123 | John Smith | 1 | 8  | 200 | 300 | 2010-03-20
  2 | J123 | John Smith | 2 | 7  | 250 | 400 | 2010-05-20
  3 | X584 | Jane Doe   | 1 | 10 | 100 | 200 | 2010-03-20
  4 | X584 | Jane Doe   | 2 | 8  | 150 | 220 | 2010-05-20
  </code></pre>
  
  <p>I've tried a few solutions but I'm lost. Any help would be great. Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>In response to the comment below, I would hope for some data like:</p>
  
  <pre><code>array  0 =&gt; 
  array
    'Exercise' =&gt; 
      array
        'person_unique_id' =&gt; string 'J123'
        'person_name' =&gt; string 'John Smith'
        'begin_mile_running_time' =&gt; string '8'
        'end_mile_running_time' =&gt; string '7'
  1 =&gt; 
  array
    'Exercise' =&gt; 
      array
        'person_unique_id' =&gt; string 'X584'
        'person_name' =&gt; string 'Jane Doe'
        'begin_mile_running_time' =&gt; string '10'
        'end_mile_running_time' =&gt; string '8'
  </code></pre>