select * from Table order by class,their,times
$result = mysql_query($sql);
$class = $their = "";
while($a = mysql_fetch_array($result)){
if($a['class']!=$class) {
if($a['their']!=$their){
$class = $a['class'];
$their = $a['their'];
echo $class.'-----'.$their.'<br>';
}}
echo views.'-----'.$times.'<br>';
}