title: Joining two tables and iterating through data
body: <p>I constantly am using stackoverflow to help me but right now I am stumped - hopefully I can get some guidance on this issue:</p>
  
  <p>I have two tables, one containing NFL Divisions the other containing NFL Teams. They are connected via the division_id field (primary key on Divisions table, foreign key on the Teams table).</p>
  
  <p>What I would like to do is join the tables in a query and output the Teams by Division. I can accomplish this in PHP with two separate queries/loops but I want to know how/if I can accomplish this by joining the two tables in a single query instead.</p>
  
  <p>Here is what I've got:</p>
  
  <pre><code>$query = "SELECT Divisions.division_id, Divisions.conference, Divisions.name, 
      Teams.name FROM Divisions INNER JOIN Teams ON 
      Teams.division_id = Divisions.division_id ORDER BY Divisions.division_id";
  
  if( $result = $db-&gt;query($query) ){
    while( $row = $result-&gt;fetch_object() ){
      // here is where I'm stuck
    }
  }
  </code></pre>
  
  <p>I'm trying to get the final output to look similar to:</p>
  
  <p><b>AFC North</b><br>
  Cleveland Browns<br>
  Pittsburgh Steelers<br>
  Baltimore Ravens<br>
  Cincinnati Bengals<br></p>
  
  <p><b>AFC East</b><br>
  Buffalo Bills<br>
  Miami Dolphins<br>
  etc..</p>
  
  <p>Major thank you in advance to anyone who can help me out with this! I haven't done any programming in over 2 years and just getting back into it.</p>