title: Nested Loop PHP MySQL results
body: <p>I am getting the results from my query but I don't seem to get the nested loop work. Here is the image that may help to explain what I am trying to do. 
  <a href="https://i.stack.imgur.com/dQJya.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dQJya.jpg" alt="enter image description here"></a></p>
  
  <p>Esentially this is what I am trying to accomplish.</p>
  
  <p><a href="https://i.stack.imgur.com/JUFCR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JUFCR.jpg" alt="enter image description here"></a></p>
  
  <p>Following is where I am having difficulty </p>
  
  <pre><code>&lt;?php
  $query = "SELECT CandidateName, CandidateVotes, Party, MainRaceName, RaceName, win
  FROM candidates
  WHERE RaceID = $RaceID";
  
    $result = mysql_query($query) or die(mysql_error());
    for($i=0; $row = mysql_fetch_array($result); $i++){
       ?&gt;
          &lt;!-- FOR LOOP 1 SHOW MainRaceName  --&gt;
        {
          &lt;h1&gt;&lt;?php echo $row['MainRaceName']; ?&gt;&lt;/h1&gt;
  
  
                      &lt;!-- FOR LOOP 2 SHOW RaceName  --&gt;
                {
                &lt;h1&gt;&lt;?php echo $row['RaceName']; ?&gt;&lt;/h1&gt;
  
  
                      {
  
                       &lt;h1&gt;&lt;?php echo $row['CandidateName']; ?&gt;&lt;/h1&gt;
                       &lt;h1&gt;&lt;?php echo $row['CandidateVote']; ?&gt;&lt;/h1&gt;
                       .
                       .
  
                      }
  
                 }
       }      
  
  
  
    &lt;?php
    }
    ?&gt;
  </code></pre>
  
  <p>You might have an easy solution and I appreciate your time and help. 
  I am working on changing the code to PDO and I am aware of the SQL injection related risks. </p>