title: Using PHP to group and display MySQL table
body: <pre><code>distID   distName   regID
  1        Khulna      1
  2        Shatkhira   1
  3        Bagerhat    1
  4        Pirojpur    1
  5        Barishal    2
  6        Barguna     2
  7        Patuakhali  2
  8        Bhola       2
  9        Jhalokathi  2
  </code></pre>
  
  <p>Hi I have the above table, and I can display data properly. I need to group regID field in the output. How can I do this? below is my php code. </p>
  
  <pre><code>&lt;?php
              include("db.php");
  
  
              $result=mysql_query("SELECT * from district d inner join region r on d.regID=r.regID");
          //  $result1=mysql_fetch_array(mysql_query("SELECT * FROM district"));
                 // echo '&lt;pre&gt;';
                  //print_r($result);
  
              while($test = mysql_fetch_array($result))
              {   //print_r($test);
                  $id = $test['distID'];  
                  echo "&lt;tr align='center'&gt;"; 
                  echo"&lt;td&gt;&lt;font color='black'&gt;" .$test['distName']."&lt;/font&gt;&lt;/td&gt;";
                  echo"&lt;td&gt;&lt;font color='black'&gt;" .$test['regName']."&lt;/font&gt;&lt;/td&gt;";
                  echo"&lt;td&gt; &lt;a href ='view.php?distID=$id'&gt;Edit&lt;/a&gt;";
                  echo"&lt;td&gt; &lt;a href ='del.php?distID=$id'&gt;&lt;center&gt;Delete&lt;/center&gt;&lt;/a&gt;";
  
                  echo "&lt;/tr&gt;";
              }
              mysql_close($conn);
              ?&gt;
  </code></pre>