I have a mysql table in this format
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 |
|_________|_________|_________|
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:
$A = array($row1,$row2,$row3);
$row1 = array("column1"=>"A", "column2"=>"val Z", "column3"=>"val Y",);
$row2 = array("column1"=>"A", "column2"=>"val X", "column3"=>"val W",);
$row3 = array("column1"=>"A", "column2"=>"val V", "column3"=>"val V",);
I hope I am clear enough. Basically I need rows to be grouped by uniqueness of values in column1.
The mysql result should contain all the rows in an array grouped as said above. something like this:
$result = array($A, $B, $C);
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:
_________________________________________________
| Header1 | Header2 | Header3 | Header4 |
|___________|___________|___________|___________|
| A | val Y | val W | val U |
|___________|___________|___________|___________|
| B | val S | val Q | |
|___________|___________|___________|___________|
| C | val O | | |
|___________|___________|___________|___________|
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.

$sql = "SELECT * FROM table;"; $result = mysqli_query($conn, $sql); $rows = mysqli_fetch_assoc($result); foreach($rows as $row){ //print_r($row); }What should I do inside the foreach loop?