title: Group mysql rows in an array by column value
body: <p>I have a mysql table in this format</p>
  
  <pre><code>Mysql table format
  _______________________________
  | column1 | column2 | column3 |
  |_________|_________|_________|
  |   A     |  val Z  |  val Y  |
  |_________|_________|_________|
  |   A     |  val X  |  val W  |
  |_________|_________|_________|
  |   A     |  val V  |  val U  |
  |_________|_________|_________|
  |   B     |  val T  |  val S  |
  |_________|_________|_________|
  |   B     |  val R  |  val Q  |
  |_________|_________|_________|
  |   C     |  val P  |  val O  |
  |_________|_________|_________|
  </code></pre>
  
  <p>What I need to do is return all rows of an occurrence of each value in column1 in an array. The array may be something like this:</p>
  
  <pre><code>$A = array($row1,$row2,$row3);
  
  $row1 = array("column1"=&gt;"A", "column2"=&gt;"val Z", "column3"=&gt;"val Y",);
  
  $row2 = array("column1"=&gt;"A", "column2"=&gt;"val X", "column3"=&gt;"val W",);
  
  $row3 = array("column1"=&gt;"A", "column2"=&gt;"val V", "column3"=&gt;"val V",);
  </code></pre>
  
  <p>I hope I am clear enough. Basically I need rows to be grouped by uniqueness of values in column1.</p>
  
  <p>The mysql result should contain all the rows in an array grouped as said above. something like this:</p>
  
  <pre><code>$result = array($A, $B, $C);
  </code></pre>
  
  <p>What I need to do with the output is display it in a table. If there is a better way of doing it please let me know. I would like the table to take this format:</p>
  
  <pre><code>_________________________________________________
  |  Header1  |  Header2  |  Header3  |  Header4  |
  |___________|___________|___________|___________|
  |    A      |   val Y   |   val W   |   val U   |
  |___________|___________|___________|___________|
  |    B      |   val S   |   val Q   |           |
  |___________|___________|___________|___________|
  |    C      |   val O   |           |           |
  |___________|___________|___________|___________|
  </code></pre>
  
  <p>This is the only way I can only think of doing it. If there is a better way of doing it please let me know. Thank you for helping.</p>