Hey.
Try something like:
<?php
$dbLink = new mysqli('host', 'user', 'pwd', 'db');
$result = $dbLink->query("... Put your query here ...");
if($result)
{
$data = array();
// Loop through all the returned rows and group the values
// into the $data array based on the 'col2' field.
while($row = $result->fetch_assoc($result)
{
$data[$row['col2']][] = $row['col1'];
}
// Loop through the 'col2' values and print a list of
// 'col1' values for each of them.
foreach($data as $_col2 => $_col1_list)
{
echo "----\n{$_col2}\n----\n";
foreach($_col1_list as $_col1)
{
echo $_col1, "\n";
}
}
}
else
{
echo "Your query phailed! " . $dbLink->error;
}
?>
If you are trying to do this sort of formatting using MySQL alone... don't. MySQL is a database system, meant to store data and return it in a very basic way.
Formatting the data for output is a job for the front-end application. (PHP, in this case.)