title: Pulling from multiple tables in a foreach loop
body: <p>Please forgive the beginner level code presented here - I'm just learning PHP and MySQL, so it should all be very base level scripting.</p>
  
  <p>My DB has two tables, teams &amp; members.  teams table has primary key teamID, which is a foreign key in the members table.  While in a foreach loop on a page that lists each member, I'm trying to access a column on the teams table by referencing the teamID column.  I've played around with it, but I either get one of two things: 1) blank returns, where it seems nothing matching is found; 2) an error that I'm trying to change an array to a string.  </p>
  
  <p>I would appreciate any insight - not for a correct answer, but more so I can understand where I'm not connecting the dots.  Thanks in advance.</p>
  
  <pre><code>&lt;?php foreach ($members as $member) : ?&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;?php echo $member['memberName']; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $member['memberDOB']; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo get_member_team(); ?&gt;&lt;/td&gt;
          &lt;/tr&gt;
  </code></pre>
  
  <p>And on my member_db.php page:</p>
  
  <pre><code>function get_member_team() {
      global $db;
      $query = 'SELECT teamName
                FROM teams
                WHERE teams.teamID = members.teamID';             
      $statement = $db-&gt;prepare($query);
      $statement-&gt;execute();
      $member_team = $statement-&gt;fetch();
      $statement-&gt;closeCursor();
      return $member_team;
  }
  </code></pre>