title: PHP MySQL multiple queries into one
body: <p>I'm trying to find a way to display my entity relations in a better way. My DB consists of 3 tables: members, fees and fees_has_members.</p>
  
  <p>One member can have multiple fees and vice versa. The problem is when I want to display all members and their corresponding fees, my while loop runs through all entities and displays all information every time it loops.</p>
  
  <p>The loop displays it like this:</p>
  
  <pre><code>Member A
  Fee B
  200 $
  
  Member A
  Fee C
  230 $
  
  Member A
  Fee B
  200 $
  </code></pre>
  
  <p>I want to display the Member once and all the related fees. </p>
  
  <p>The code:</p>
  
  <pre><code> &lt;?php 
  mysql_connect("#######", "########", "######") or die(mysql_error());
  mysql_select_db("#####") or die(mysql_error());
  ?&gt;
  
  &lt;h3&gt;Members:&lt;/h3&gt;
  &lt;?php
   $result = mysql_query("SELECT boder_boder_id, medlemmer_medlemmer_id, medlemmer_navn, medlemmer_id, boder_navn, boder_id, boder_pris FROM boder_has_medlemmer, medlemmer, boder WHERE boder_boder_id = boder_id AND medlemmer_medlemmer_id = medlemmer_id");
   ?&gt;
  
   &lt;?php
   if (mysql_num_rows($result) == 0)
   echo "Query returned 0 rows";
   ?&gt;
  
   &lt;?php
   $samlet = 0;
   while($row = mysql_fetch_array($result))
   { ?&gt;
  
   &lt;p&gt;
   &lt;?php
    echo $row[medlemmer_navn].'&lt;br&gt;'; 
    echo $row[boder_navn].'&lt;br&gt;';
    echo $row[boder_pris].' kr.';
    $samlet += $row[boder_pris];
   ?&gt;
   &lt;/p&gt;
  </code></pre>
  
  
  
  <p>I know i could change the MySQL query to include the specific member name, but then I would have to run 30 queries to display all members and their fees.</p>
  
  <p>I hope I made myself clear.</p>
  
  <p>Any suggestions?</p>